What will happened when writing switch case with "break" in a for loop
zhou-yg

zhou-yg @zhouyg

About: a frontend magician. author of tarat.js

Joined:
Aug 2, 2022

What will happened when writing switch case with "break" in a for loop

Publish Date: Sep 14 '22
0 0

demonstration code:
javascript
const arr = [1,2,3];
for (const n of arr) {
switch (n) {
case 1: console.log(n); break;
default: console.log(n); break;
}
}

Amazing! the "break" keyword won't break the for loop

Comments 0 total

    Add comment