Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
249 views
in Technique[技术] by (71.8m points)

javascript - 在JavaScript中声明多个变量(Declaring Multiple Variables in JavaScript)

In JavaScript, it is possible to declare multiple variables like this:(在JavaScript中,可以这样声明多个变量:)

var variable1 = "Hello World!"; var variable2 = "Testing..."; var variable3 = 42; ...or like this:(...或像这样:) var variable1 = "Hello World!", variable2 = "Testing...", variable3 = 42; Is one method better/faster than the other?(一种方法比另一种方法更好/更快吗?)   ask by Steve Harrison translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The first way is easier to maintain.(第一种方法更易于维护。)

Each declaration is a single statement on a single line, so you can easily add, remove, and reorder the declarations.(每个声明都是一行上的单个语句,因此您可以轻松地添加,删除和重新排序声明。) With the second way, it is annoying to remove the first or last declaration because they contain the var keyword and semicolon.(使用第二种方法时,删除第一个或最后一个声明很烦人,因为它们包含var关键字和分号。) And every time you add a new declaration, you have to change the semicolon in the old line to a comma.(每次添加新的声明时,都必须将旧行中的分号更改为逗号。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...