0

I'm fairly new to Javascript, and filled with questions, most of which I'm able to find the the answers to online. However, there is the rare occurrence when my wording of a question doesn't correctly communicate the idea I'm trying to portray. That's when I come to Stack Overflow, and try to communicate more visually.

line break
Which of these two examples is more commonly acceptable when programming with Javascript?

Method 1:

var one = 1;
var two = 2;

Method 2:

var one=1,
    two=2;

line break
Are there more specific (organizational) occasions when Method 2 should be used?

Example:

// Food
var pizza,
    sushi,
    cheeseburger;

// Utensils
var fork,
    spoon,
    excalibur;

line break
Just in-case you believe the answer to this question is purely subjective, I pose a different question for you: which way (in terms of storage) is more efficient, and is the size of the difference insignificant for larger-scale web apps?

Elegant.Scripting
  • 757
  • 4
  • 10
  • 28
  • It is personal preference on style. There is really no difference in storage. File size difference is going to be how many extra vars you have. – epascarello Jan 27 '15 at 17:31
  • It's just style, there should be no impact on the operation of the script. – Barmar Jan 27 '15 at 17:31
  • Duplicate post to: http://stackoverflow.com/questions/3781406/javascript-variable-definition-commas-vs-semicolons – Alex Jan 27 '15 at 17:35

1 Answers1

0

The virtual machine treats the two identically. There will be no performance difference between the two. Stylistically some developers prefer the former, while I have always used the latter. Ultimately whatever you find more readable and whatever is the communalized standard at your organization is the one to go with.

Gabriel
  • 18,322
  • 2
  • 37
  • 44