Explore 100's Of Free Video Tutorials

Keep Learning, Keep Coding & Keep Sharing

Variables Vs Constants - Part 1

Notes:

JavaScript Variables Vs. JavaScript Constants:

Variable:
Variable is a named memory location, whose value may change during the execution of a program.

Constant:
Constant is a named memory location, whose value never changes during the execution of a program.
I.e. constants stay constant whereas variables vary.

In order to grab a chunk of memory location, provide meaningful name and use it, we need to declarare a variable or a constant
Declaring a variable or a constant: means allocating a memory location for some data

In order to change the value in a variable or constant, we need to initialize or assign a value to it.
Initializing a variable or a constant: means putting a data value in that allocated memory location

Syntax:
var nameOfVariable; // declaration of a variable
nameOfVariable = value; // initialization of a variable

const NAME_OF_CONSTANT = value; // declaration and initialization of a constant

Note:
By default the value of a variable will be undefined.
By default the value of a constant will be uninitialized, will lead to an error.

Interview Questions: