aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Statement var changed = [], n, c, def, o, ol, opt; Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Statement var changed = [], n, c, def, o, ol, opt;" Watch "Statement var changed = [], n, c, def, o, ol, opt;" New topic
Author

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

Joe Brigs
Ranch Hand

Joined: Jun 06, 2011
Posts: 60

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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Jan 10, 2002
Posts: 60997
    
  65

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!


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Bear,

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

Eric
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65

Huh?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Jan 10, 2002
Posts: 60997
    
  65

Still not sure what you meant to begin with. I use strict mode for most new script.
Joe Brigs
Ranch Hand

Joined: Jun 06, 2011
Posts: 60

Thank you Guys !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Statement var changed = [], n, c, def, o, ol, opt;