Skip to content
Browse files

bad practice: undeclared global variable

  • Loading branch information...
1 parent 5aa6fa4 commit 7b66dd36fee610ae911345fc6ab92ac0984f5682 @ealize committed
Showing with 1 addition and 1 deletion.
  1. +1 −1
@@ -210,7 +210,7 @@ The benefit of this architecture is that each component plays its own separate r
var buildPhotoView = function( photoModel, photoController ){
var base = document.createElement('div'),
- photoEl = document.createElement('div');
+ var photoEl = document.createElement('div');

This is incorrect. The variable is being declared in a sequence of variable declarations separated by a comma.

var base    = document.createElement('div'),
    photoEl = document.createElement('div');

is equivalent to

var base = document.createElement('div');
var photoEl = document.createElement('div');

In this commit you now have

var base = document.createElement('div'),
var photoEl = document.createElement('div');

which is bad (there is now an unnecessary var after a comma).
Either of the first two styles of variable declaration works, but var after a comma does not (try running var x=1, var y=2 in your console).

I often use the second style to declare long lists of variables with less typing and to make code more readable, e.g.:

var one   = 1
,   two   = 2
,   three = 3
,   four  = 4

Read more about the JavaScript comma operator here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

0 comments on commit 7b66dd3

Please sign in to comment.
Something went wrong with that request. Please try again.