Previous Page : JavaScript Comments

JavaScript variables are used to store data values. They are containers for storing data values. They are similar to variables in other programming languages and are used to store data values, such as numbers, strings, or objects.

💢 Declaring Variables:

In JavaScript, a variable is declared using the var, let, or const keyword.

var x;  // Declare a variable named x
let y;  // Declare a variable named y
const z = 0;  // Declare a constant variable named z and initialize it with a value of 0

The var ****keyword is used to declare a variable in JavaScript. You can assign a value to a variable by using the assignment operator ( = ).

var x;
x = 5;  // Assign the value 5 to the variable x

The let keyword is used to declare a variable, it is similar to var but with a difference that variables declared with let are block scoped and not function scoped like var.

let y = "Hello"; // Declare and initialize the variable y with the value "Hello"

The const keyword is used to declare a constant variable, which means that the value of the variable cannot be changed once it is assigned.

const z = 0; // The value of z cannot be changed

Data Types: JavaScript supports several data types, including: