Var Let and Const 1727372287
Var Let and Const 1727372287
Enthusiasts
VAR 01
Scope: Function-scoped, meaning if it's declared
inside a function, it will be available throughout
the entire function.
Re-declaration: You can re-declare a var variable
within the same scope without any errors.
Hoisting: var declarations are hoisted to the top of
their scope, meaning they can be accessed even
before they are declared (but the value will be
undefined until assignment)
Salesforce LWC & JavaScript
Enthusiasts
LET 02
Scope: Block-scoped, meaning it is only available
within the block (e.g., {}) in which it was declared.
Re-declaration: You cannot re-declare a let
variable in the same scope, but you can reassign
its value.
Hoisting: Like var, let is hoisted, but it's not
initialized. Accessing it before declaration results
in a ReferenceError
Salesforce LWC & JavaScript
Enthusiasts
CONST
Scope: Block-scoped, similar to let.
03
Re-declaration & Re-assignment: You cannot re-
declare or reassign a const variable. Once a value
is assigned, it can't be changed. However, if the
variable holds an object or array, the properties of
the object or elements of the array can be
changed (but the reference cannot).
Hoisting: Like let, const is hoisted but not
initialized, and accessing it before declaration
results in a ReferenceError