0% found this document useful (0 votes)
27 views4 pages

Var Let and Const 1727372287

The document explains the differences between var, let, and const in JavaScript. Var is function-scoped and allows re-declaration, while let is block-scoped and does not allow re-declaration but allows reassignment. Const is also block-scoped, does not allow re-declaration or reassignment, but allows modification of object properties or array elements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views4 pages

Var Let and Const 1727372287

The document explains the differences between var, let, and const in JavaScript. Var is function-scoped and allows re-declaration, while let is block-scoped and does not allow re-declaration but allows reassignment. Const is also block-scoped, does not allow re-declaration or reassignment, but allows modification of object properties or array elements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Salesforce LWC & JavaScript

Enthusiasts

VAR, LET AND


CONST
Salesforce LWC & JavaScript
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

You might also like