0% found this document useful (0 votes)
5 views9 pages

JavaScript Variable Declarations Explained

The document discusses variable declarations in JavaScript, focusing on 'var', 'let', and 'const'. It highlights that 'const' cannot be reassigned, 'var' can be redeclared, and 'let' can be reassigned but not redeclared in the same scope. Additionally, it briefly mentions primitive and non-primitive data types.

Uploaded by

P.V. AADI VISHNU
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)
5 views9 pages

JavaScript Variable Declarations Explained

The document discusses variable declarations in JavaScript, focusing on 'var', 'let', and 'const'. It highlights that 'const' cannot be reassigned, 'var' can be redeclared, and 'let' can be reassigned but not redeclared in the same scope. Additionally, it briefly mentions primitive and non-primitive data types.

Uploaded by

P.V. AADI VISHNU
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

let, var, const

Some what correct. Will discuss more while


assigning objects to variables
Memory
10020
10022
10024 ?
10026 2000
10028
10030
10032
10034
10036
10038
10040
10042
10044 3000
const
• Variables declared using const
cannot be reassigned.

• They are called constants

• Used to avoid mistakes

• It is a best practice to write


constants in UPPER CASE
var
• Variables declared with var can be
redeclared

• var is the only keyword used to


create variables till 2015

• let and const were introduced in ES6


(ECMAScript 2015)
var let const
Variables declared with Variables declared with let Variables declared with
var can be re-assigned and can be re-assigned but const cannot be re-
re-declared within the cannot be re-declared in assigned or re-declared.
same scope the same scope But…
It is recommended to Preferred for variables Best for variables that
avoid using var in modern that may need to change should not be reassigned.
JavaScript. value To avoid mistakes.

Will discuss after talking about


scopes and hoisting
Some what correct. Will discuss more while
assigning objects to variables
Memory
10020
10022
10024 ?
10026 2000
10028
10030
10032
10034
10036
10038
10040
10042
10044 3000
8 Data Types

Primitive Data Types Non - Primitive Data Types

1. number 1. object
2. string
3. boolean
4. null
5. undefined Will discuss more
6. bigint about it later
7. symbol
Chapter 15

statements

You might also like