Why "let = 13" don't throw an error in JavaScript? (Chrome console + nodejs)

Viewed 44

"var, let, const" are keywords in JS, you can not name your variables with keywords. but if you try to declare a variable named "let", it will work and throw no error.

e.g.

const = 13; //Uncaught SyntaxError: Unexpected token '='
var = 13; //Uncaught SyntaxError: Unexpected token '='
const let = 123; //Uncaught SyntaxError: let is disallowed as a lexically bound name
let let = 13; //Uncaught SyntaxError: let is disallowed as a lexically bound name
x = 13; //works good, so far so good

let = 13; //works fine,
++let // returns 14

at first, I thought because "let" is a new keyword (ES2015) so it's backward compatibility or something like that, but you can't do it with the const keyword or any JS keyword

anyone knows why?

0 Answers
Related