4

A small question:

In my Browser(GoogleChrome) console if I type

abc:xyz:123

it evaluates to

123

How does JavaScript evaluate :?

thefourtheye
  • 206,604
  • 43
  • 412
  • 459
Jyoti Puri
  • 1,196
  • 8
  • 16

2 Answers2

10

Both abc and xyz are treated as loop labels. Quoting from MDN,

Provides a statement with an identifier that you can refer to using a break or continue statement.

For example, you can use a label to identify a loop, and then use the break or continue statements to indicate whether a program should interrupt the loop or continue its execution.

Also, check Avoid using labels section,

Labels are not very commonly used in JavaScript since they make programs harder to read and understand. As much as possible, avoid using labels and, depending on the cases, prefer calling functions or throwing an error.

thefourtheye
  • 206,604
  • 43
  • 412
  • 459
3

I believe what is happing is abc and xyz are being treated as labels. So 2 labels are being created and then the statement of 123 is being evaluated which gives you the result of 123

pgreen2
  • 3,469
  • 3
  • 27
  • 53