DEV Community

Anandhi P
Anandhi P

Posted on

Variables

A variable is a container used to store a value in JavaScript.

Example:
let name = "Anandhi";
let age = 21;

Here:

name → variable
"Anandhi" → value
age → variable
21 → value

Types of Variables

JavaScript has 3 keywords to declare variables:

var – old way
let – value can be changed
const – value cannot be reassigned

Example:
let age = 21;
age = 22;
Here, age changes from 21 to 22.
const pi = 3.14;
pi cannot be reassigned.

Simple definition:
A variable is a named container that stores data in JavaScript.

Top comments (0)