ASHWINTH** JavaScript Variables: let, const, and var** JavaScript provides three keywords to declare...
** JavaScript Variables: let, const, and var**
JavaScript provides three keywords to declare variables: let, const, and var.
let
let is used when a variable's value may change.
javascript
let age = 20;
age = 21;
const
const is used when a variable should not be reassigned.
javascript
const name = "John";
Trying to change it will cause an error:
name = "Mike"; // Error
var
var is the older way to declare variables in JavaScript.
var city = "Chennai";
city = "Mumbai";
In modern JavaScript, let and const are generally preferred over var because they have clearer scoping rules.
Quick Summary
let → value can be changedconst → value cannot be reassignedvar → older variable declaration methodUnderstanding these three keywords is an essential first step in learning JavaScript.