如何在一條 JavaScript 語句中宣告並定義多個變數?


要在一份語句中宣告並定義多個變數,可以使用以下語法 −

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

更新日期: 14-Sep-2020

236 次瀏覽

開啟你的職業 生涯

完成本課程即可獲得證書

開始
廣告
© . All rights reserved.