-
Notifications
You must be signed in to change notification settings - Fork 0
/
Object.js
57 lines (41 loc) · 1.68 KB
/
Object.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
// singleton
// create Object by constrocter method
// Object.create
// object literals //object declearation
let mysymb=Symbol("key1")
const iam={
name:"Abhishek",
age:18,
"full name":"Abhisek pandey ",
[mysymb]:"mykey1",//[] we are using for symbol
email:"abhishek@google.com",
IsloggedIn:true,
Last_logindays:["sunday","monday"]
} //this is an object now if we will give value in this then we can acces that value
// in array we can use we can acces valu by position of array but in object we will provide a key for any value and will acesss by key
// javascript will take key as a string
// how to acces object
// console.log(iam.email);
// console.log(iam["email"]); //there are two way to acces object
// console.log(typeof mysymb);
//here we will neeed to use squre bracket cause here we can not use .full name or ."full name" we can access like this ["full name"]
console.log(iam["full name"])
// change value from object
iam.email="abhitechops@gmail.com"
// freez an object then we can not change object values
Object.freeze(iam)
iam.name="abhi"
// for use symbol in object as a symbol we will use squre bracket in key they will can acces key as a symbol
// console.log(iam);
// we can treet function as variable
// it is a way to create a fuction for an object
// iam.greeting=function(){
// console.log(`hello,${this.name} your age is ${this.age} `);
// }
// we can also create function like this
function greetingg (){
console.log(`hello ${iam.name} your age is ${iam.age} `);
}
console.log(greetingg());
// console.log(greetingg()); //if we will not give bracket then will get function reference
// but if we want to acces function we need to use bracket