jimfog Posted March 22, 2013 Share Posted March 22, 2013 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 More sharing options...
jeffman Posted March 22, 2013 Share Posted March 22, 2013 (edited) 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 March 22, 2013 by Deirdre's Dad Link to comment Share on other sites More sharing options...
jimfog Posted March 23, 2013 Author Share Posted March 23, 2013 thanks for the explanation...I am not surprised with the answer. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now