Jump to content

javascript syntax explained


jimfog

Recommended Posts

This is a javascript code example:

var object = {    'foo': 'bar'},num = 1;

Does num has anything to do with the object creation above?The brackets(I think) mean the end of the declaration of the objectbut the comma after the closing bracket manages to confuse me. So...I little help is needed here.Thanks

Link to comment
Share on other sites

This is one statement that declares and initializes two variables. Compare:

var a;var i = 0;var s = "Hello";

To save space and a VERY small amount of computing time, that can be simplified to this:

var a, i = 0, s = "Hello";

Because JavaScript ignores most line breaks, the code you showed could be written like this:

var object = {'foo': 'bar'}, num = 1;

Which is the same as this:

var object = {'foo': 'bar'};var num = 1;

Edited by Deirdre's Dad
Link to comment
Share on other sites

thanks for the explanation...I am not surprised with the answer.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...