Is there a benefit to defining variables together with a comma vs separately in JavaScript? -


reading crockfords the elements of javascript style notice prefers defining variables this:

var first='foo', second='bar', third='...'; 

what, if benefit method provide on this:

var first='foo'; var second='bar'; var third='...'; 

obviously latter requires more typing aside aesthetics i'm wondering if there performance benefit gained defining former style.

aside of aesthetics, , download footprint, reason var statement subject hoisting. means regardless of variable placed within function, moved top of scope in defined.

e.g:

var outside_scope = "outside scope"; function f1() {     alert(outside_scope) ;     var outside_scope = "inside scope"; } f1(); 

gets interpreted into:

var outside_scope = "outside scope"; function f1() {     var outside_scope; // undefined     alert(outside_scope) ;     outside_scope = "inside scope"; } f1(); 

because of that, , function-scope javascript has, why crockford recommends declare variables @ top of function in single var statement, resemble happen when code executed.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -