
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
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
- Related Articles
- How to assign same value to multiple variables in single statement in C#?
- Assign multiple variables with a Python list values
- How to assign multiple values to a same variable in Python?
- How to assign multiple values to same variable in C#?\n
- Multiple Variables Holding Data - Which has the Highest Value in JavaScript?
- How do we assign a value to several variables simultaneously in Python?
- How to concatenate multiple string variables in JavaScript?
- How to assign values to variables in C#?
- How to assign values to variables in Python
- How to use the same JavaScript in multiple content pages?
- How do we assign values to variables in Python?
- New ways to Assign values to Variables in C++ 17 ?
- What is the best way of declaring multiple Variables in JavaScript?
- Map multiple properties in array of objects to the same array JavaScript
- Assign value to unique number in list in Python

Advertisements