Jump to content

object creation syntax


jimfog

Recommended Posts

Recently, in a tutorial I came across with this syntax:

var prop, obj = { name: "Joe", job: "Coder", age: 25 };  

I really cannot understand what the prop is doing there.

 

It is like assigning the object to 2 variables, furthermore in the w3schools tutorials about object creation

I saw nowhere similar syntax.

 

So, what the above means?

Unless the writer of the code is making a mistake.

Link to comment
Share on other sites

A single var keyword can initialize an arbitrary number of variables as long as they are separated by a comma. At the same time, you can set an initial value for any of them. In this case, only the second variable is being initialized to a value.

Link to comment
Share on other sites

got it,thanks both of you

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...