Saturday, September 6, 2025
HomeLanguagesJavascriptHow to declare multiple Variables in JavaScript?

How to declare multiple Variables in JavaScript?

In this article, we will see how to declare multiple Variables in JavaScript. The variables can be declared using var, let, and const keywords. There are different methods to declare multiple variables, these are:

Declaring Variables Individually: In this case, we will declare each variable using the var, let, or const keywords.

Syntax:

let x = 20;
let y = 30;
let z = 40;

 

Example:

Javascript




let x = 20;
let y = 'G';
let z = "neveropen";
  
console.log("x: ", x);
console.log("y: ", y);
console.log("z: ", z);


Output

x:  20
y:  G
z:  neveropen

Declaring Variables in a Single Line: You can declare multiple variables in a single line using the var, let, or const keyword followed by a comma-separated list of variable names.

Syntax:

let x = 20, y = 30, z = 40;

Example:

Javascript




let x = 20,
    y = 'G',
    z = "neveropen";
  
console.log("x: ", x, "\ny: ", y, "\nz: ", z);


Output

x:  20 
y:  G 
z:  neveropen

Using Destructuring Assignment: You can also use de-structuring assignments to declare multiple variables in one line and assign values to them.

Syntax:

const [var1, var2, var3] = [val1, val2, val3];

Example:

Javascript




const [x, y, z] = [20, 'G', "neveropen"];
  
console.log("x: ", x, "\ny: ", y, "\nz: ", z);


Output

x:  20 
y:  G 
z:  neveropen
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32269 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6638 POSTS0 COMMENTS
Nicole Veronica
11802 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11868 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7029 POSTS0 COMMENTS
Thapelo Manthata
6704 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS