-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay10Symboltype.html
42 lines (32 loc) · 1.09 KB
/
Day10Symboltype.html
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
<!DOCTYPE html>
<html>
<head>
<title>
Day10
</title>
</head>
<body>
<script>
// Symbol() is a new primitive type added in ES6
let something= Symbol();
let thing = Symbol();
console.log(something==thing)// false
// because each time when we create symbol
// it is new identifier , it is uniquie
let newvalue=Symbol("hello")
console.log(newvalue); // symbol(hello) ---- output
// alert(something)// alert acpts string type ,so it will give error
alert(newvalue.toString())// Symbol(hello)
alert(newvalue.description);// hello --- will be printed
let sym= Symbol.for("name")// gobal registry
let sym1=Symbol.for("firstname")
console.log(Symbol.keyFor(sym));//name
//object
let firstname=Symbol("firstname");
let person={
[firstname]:"ponmani"
}
console.log(firstname);
</script>
</body>
</html>