Just a simple question?


#1

var bob = {
firstName: "Bob",
lastName: "Jones",
phoneNumber: "(650) 777-777",
email: "bob.jones@example.com"
};

seeing the code above I totally understand it but one little confusing thing, is bob being referred to as an associative array here. Is this not an object created using object literal?


#2

what they are trying this object literal notation is analogous to associative arrays in some languages like PHP. Where you generally have keys(properties) associated with values


#3

This is a object literal notation you should use this notation if you wanna make a associative array.

Short way

var bob = {
    firstName: "Bob",
    lastName: "Jones",
    phoneNumber: "(650) 777-777",
    email: "bob.jones@example.com"
};

The braces define an unnamed object without a class . The quotes around the keys are optional . Only if the term contains spaces , quotes must be placed around the key concept .

Expensive way

var bob = new Array();
bob["firstName"] = "Bob";
bob["firstname"] = "Jones";
bob["phoneNumber"] = "(650) 777-777";
bob["email"] ="bob.jones@example.com";