+ 7
Javascript question
myBlock: { var a = 0; break myBlock; a = 1; } console.log(a); // 0 Why is the result here 0? Shouldnt it be a syntax error?
10 Respostas
+ 16
David
because u are using break statement
after break statement all code are useless
which means
a = 1 will not work
+ 5
David
Using the break statement with a label is legal as long as it is nested within the referenced labeled statement", in this case, myBlock.
more on the subject-
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/break#break_in_labeled_blocks
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/break
+ 2
After break statement the next code will be skipped that's why
+ 1
ODLNT thank you for your help, will read it
+ 1
No problems, I'm glad I could help.
0
Pariket Thakur I get this, but I dont understand why this syntax myBlock: {} is not recognized as a syntax error
0
myBlock: {
a = 0;
break;
a = 1;
}
console.log(a); // 0
Try this and you will get a syntax error.
- 1
You Will Get syntex error
- 1
I yet gcjxy vcnbcgxt xh such ucfbtxvkyc