Rohit Sachdeva Rohit Sachdeva - 2 months ago 5
Javascript Question

How to defined nested object in Javascript?

I am new to Javascript, I am trying to create the following but not able run it , Please help me with the error in the syntax of the nested objects in this small code snippet:

var Employee = {

name: "Rohit Sachdeva", // Defining the Object with the details
storeName : "Van Heusen",
age : 29,
salary : 30000

address: {

"address1": {


cityName : "Bengaluru",
state : "Karnataka",
pinCode: 560078
}

}


};

Answer

You need a comma after salary salary: 30000,

var Employee = {
  name: "Rohit Sachdeva",                  
  storeName : "Van Heusen",
  age : 29,
  salary : 30000,
  address: {
    "address1": {
      cityName : "Bengaluru",
      state : "Karnataka",
      pinCode: 560078 
     }
  }
};