01. BASICS | Variables in JavaScript
This article will talk about javascript variables.
var
- Can be re-declared and updated within its scope.
var name = "Shubham";
// ✅ Below operations are possible
name = "Amit"; // only updating
var name = "Amit"; // re-declaration and updating
- It is not compulsory to initialize a
varvariable during declaration.
var name;
let
- Can be updated but not re-declared.
let name = "Shubham";
name = "Amit"; // can be updated
// ❌ Below operation is not possible
let name = "Amit"; // re-declaration and updating
- It is not compulsory to initialize a
letvariable during declaration.
let name;
const
- Can neither be re-declared nor updated.
const name = "Shubham";
// ❌ Below operations are not possible
name = "Amit"; // only updating
const name = "Amit"; // re-declaration and updating
- Must be initialized during declaration.
// ❌ Only declaration is not possible
const name;
Rules for choosing variable names
Only letters, digits, underscore(
_) and dollar($) allowed.Must begin with a letter or
_or$. Must not begin with a digit.JavaScript reserved words can't be used as a variable name.
Variable names are case sensitive (name, Name and NaMe are different variable names).
Happy reading!

