How can I declare and define multiple variables in one statement with JavaScript?

JavascriptWeb DevelopmentObject Oriented Programming

To declare and define multiple variables in one statement, you can use below syntax −

var anyVariableName1=yourValue1,
anyVariableName2=yourValue2,
anyVariableName3=yourValue3,
anyVariableName4=yourValue4,
.
.
N

Example

var firstName="My First Name is David",
lastName="My Last Name is Miller",
place="I live in AUS";
console.log(firstName);
console.log(lastName);
console.log(place);

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

node fileName.js.

Here, my file name is demo182.js.

Output

This will produce the following output −

PS C:\Users\Amit\javascript-code> node demo182.js
My First Name is David
My Last Name is Miller
I live in AUS
raja
Published on 14-Sep-2020 06:35:56
Advertisements