Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

Assign multiple variables to the same value in JavaScript?



To assign multiple variables to the same value, the syntax is as follows

var anyVariableName1,anyVariableName2,anyVariableName3……….N;
yourVariableName1=yourVariableName2=yourVariableName3=.........N=yourValue;

Let’s say the following are our variables and we are assigning same value −

var first,second,third,fourth,fifth;
first=second=third=fourth=fifth=100;

Example

var first,second,third,fourth,fifth;
first=second=third=fourth=fifth=100;
console.log(first);
console.log(second);
console.log(third);
console.log(fourth);
console.log(fifth);
console.log("The sum of all values="+(first+second+third+fourth+fifth));

To run the above program, you need to use the following command −

node fileName.js.

Here, my file name is demo114.js.

Output

This will produce the following output −

PS C:\Users\Amit\JavaScript-code> node demo114.js
100
100
100
100
100
The sum of all values=500
Updated on: 2020-09-09T13:10:44+05:30

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements