- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements
To Continue Learning Please Login
Login with Google