-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject.js
More file actions
26 lines (22 loc) · 902 Bytes
/
object.js
File metadata and controls
26 lines (22 loc) · 902 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//There are three common ways to build objects
//1.Object literals and the dot notation: One of the most common ways of building an object in JavaScript is using the object literal syntax: {}.
var user = {}; //create an object
user.money = "100000$" ;
user.age = 28;
user.health = "normal";
user.id = 32;
console.log(user);
//2.key-value pair
var table = {
legs: 3,
color: "brown",
priceUSD: 100,
}
console.log(table);// returned value is the entire table object
console.log(table.color);// I can console log any individual property like this
//3.Object literals and the brackets notation. There is an alternative syntax to the dot notation I used up until this point. This alternative syntax is known as the brackets notation.
var house2 = {};
house2["rooms"] = 4;
house2['color']= "pink";
house2["priceUSD"] = 12345;
console.log(house2); // {rooms: 4, color: 'pink', priceUSD: 12345}