flightlessbird
flightlessbird

Reputation: 423

Why can invoked functions be prefixed with a name + colon in JavaScript

I found this code snippet in some very old JS code (simplified to a working example):

foo:console.log('I have a prefix')

This works and logs as you would expect. What is going on here? I initially thought this would be a syntax error. (note that the original form I discovered this in was as javascript:foo()).

Upvotes: 3

Views: 36

Answers (1)

dfsq
dfsq

Reputation: 193261

This is a lable statement, not very common feature. But sometimes you can see them in nested loops for example, to name loop in order to reference it later to break it or continue.

Of course in your example with console.log it's totally useless and confusing.

Reference: Labeled statements.

Upvotes: 4

Related Questions