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



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
Updated on: 2020-09-14T06:36:57+05:30

302 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements