🔰variable
JS ⟩ variable
a variable has a valueand an identifier as its name.
assignment to an undeclared identifier will result in an accidental global variable in sloppy mode❗️ in sloppy mode.
variables just been declared will be assigned undefined automatically (with some nuances).
var hoisting - declaration hoisted, value initialized to "undefined".
let/const/class hoisting - declaration hoisted, value "uninitialized"❗️
const requires initialization - must declare with initial value❗️
function hoisting - declaration hoisted, value initialized to a function.
(other than declaration) all occurrences of variables/identifiers serve in one of two "roles":
the target of an assignment. (LHS reference)
the source of a value. (RHS reference)
// ⭐️ states of an identifier/variable (in a specific scope)
// • undeclared identifier
// -> uninitialized variable (declared but undefined)
// -> initialized variable (with value !== undefined)
declaring variables
parameter - parameters are variables.
referencing variables
undeclared identifier - how to check if a variable is undeclared?
temporal dead zone of a let/const variable.
variable hoisting
compare:function hoisting
let declares a block scoped local variable.
Last updated