-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path14_objects.js
61 lines (43 loc) · 1.47 KB
/
14_objects.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
In JavaScript, almost "everything" is an object.
JavaScript object is a collection of named values
Booleans can be objects (if defined with the new keyword)
Numbers can be objects (if defined with the new keyword)
Strings can be objects (if defined with the new keyword)
Dates are always objects
Maths are always objects
Regular expressions are always objects
Arrays are always objects
Functions are always objects
Objects are always objects
All JavaScript values, except primitives, are objects.
There are different ways to create new objects:
Create a single object, using an object literal. //
Create a single object, with the keyword new.
Define an object constructor, and then create objects of the constructed type.
Create an object using Object.create().
JavaScript Objects are Mutable
Objects are mutable: They are addressed by reference, not by value.
Singleton object made with constructor
whereas whenever we make object with literals, it wont create a singleton object
*/
//1]Object literals
// const fruits = {name:"yadnyesh",rollNO:36,dept:"aiml"}
let obj1 = {
name: "yadnyesh",
rolNO: 36,
dept: "aiml"
}
// console.log(obj1.hasOwnProperty("fllor"))
// // console.log(obj1.toLocaleString("name"))
// const str=obj1.toString
//
const person = {
fname:"John",
lname:"Doe",
age: 25
};
// for (let x in person) {
// console.log(person[x]);
// }
// console.log(`My name is ${person.fname} and my surname is ${person.lname}. my age is ${person.age}`);