Nevermind
Nevermind

Reputation: 33

Why putting colon before variable name is a valid code in js?

Example:

let :test = "Hello";
console.log(test);

This code doesn't throw any error. Why?

Upvotes: 3

Views: 149

Answers (1)

epascarello
epascarello

Reputation: 207521

Because you actually have a label https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label

If you were in strict mode, it would have thrown an error.

let: // <-- label
  test = "hello 

Upvotes: 5

Related Questions