We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 9f132f7 commit efe0dd4Copy full SHA for efe0dd4
stack-learner/chapter-07/02literal-vs-constructor.js
@@ -0,0 +1,39 @@
1
+
2
+// 51. Object Literal vs Constructor in JS
3
4
+/*
5
+ Object Property = key:value pair | name:value pair
6
+*/
7
8
+var obj = {}
9
+console.log(obj) // {}
10
+console.log(typeof obj) // object
11
12
+obj.x = 10
13
+console.log(obj) // { x: 10 }
14
15
+// 1. Object Literal
16
17
+var point = {
18
+ x: 10,
19
+ y: 20
20
+}
21
+console.log(point) // { x: 10, y: 20 }
22
23
+point.y = 30
24
+point.z = 50
25
+console.log(point) // { x: 10, y: 30, z: 50 }
26
27
+// 2. Object Constructor (Used in OOP)
28
29
+var obj1 = Object()
30
+obj1.a = 10
31
32
+var obj2 = new Object()
33
+obj2.b = 20
34
35
+console.log(obj1) // { a: 10 }
36
+console.log(obj2) // { b: 20 }
37
38
39
0 commit comments