Why doesn't the word: at the beginning of some JavaScript statements produce syntax errors?

Apparently, if you run something like wth:alert('hi') from the console, it just works, cross browser.

The whatever: bit whatever: behaves like a window. when used at the beginning of instructions, for that matter.

I think this is useless, but I'm curious. Unable to find any explanation or corresponding operator.

+4
source share
1 answer

What you see here is a label .

They are used for most incredulous flow control methods, namely goto (fortunately, it is not supported in Javascript). The general use of these methods is intended to directly instruct the program to "go" to a position in the code that inadvertently leads to spaghetti code .

+5
source

Source: https://habr.com/ru/post/1388102/


All Articles