如何使用 JavaScript 在一个语句中声明和定义多个变量?

javascriptweb developmentobject oriented programming更新于 2025/11/18 8:44:17

要在一个语句中声明和定义多个变量,可以使用以下语法 −

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

示例

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);

要运行上述程序,您需要使用以下命令 −

node fileName.js.

这里,文件名是 demo182.js。

输出

这将产生以下输出 −

PS C:\Users\Amit\javascript-code> node demo182.js
My First Name is David
My Last Name is Miller
I live in AUS

相关文章


有用资源