• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Statement var changed = [], n, c, def, o, ol, opt;

 
Joe Brigs
Ranch Hand
Posts: 70
IBM DB2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a novice to JavaScript so I'm Sure this is simple and I have my ideas but I only have come accross this once and not sure what its doing.

Is this creating an Array called "changed" and making it 6 long ( 6 variables ? ) because the code that follows this assigns values to each,
( i.e. c = false , def = 0) Any help. Thanks
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is just defining a bunch of variables and only the first one is an array, the rest are undefined values.

It might more sense if it was written on their own lines


which is the same thing as doing



If you code JavaScript in strict mode, you can only have one variable declaration for each block scope.

Eric
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65118
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I never use that form. It's too confusing. I use one per line, each with their own var keyword as in Eric's last example.

I also rarely declare so many global variables. Closures, people, closures!
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear,

You do not use strict mode? Shame on you! ;)

Eric
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65118
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Huh?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear,

Did you not talk about it in the latest book? http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/

Eric
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65118
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still not sure what you meant to begin with. I use strict mode for most new script.
 
Joe Brigs
Ranch Hand
Posts: 70
IBM DB2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Guys !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic