JS: Variable
for JavaScript code after ECMAScript 2015, you need to declare variable.
// declare a variable and assign a value let x = 4; console.log(x); // 4
// If a variable is not assigned, it has a value of undefined let x; console.log(x === undefined);
Historical note
in JavaScript before ECMAScript 2015, variable do not need to be declared.
You can simply assign it e.g. x = 3.
It becomes property of
the Global Object
.
After ECMAScript 2015 , variable needs to be declared, by using let or const.
In Strict Mode, variable also need to be declared.