Skip to content

Commit 1af4f1c

Browse files
committed
try practicing about the spread operator as it is important here
1 parent 3d0a59c commit 1af4f1c

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

wrapper.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
let a ="hello"
2+
let b = new String ("hello")
3+
console.log(typeof a)
4+
console.log(typeof b)
5+
6+
console.log(a==b)
7+
console.log(a===b)
8+
// why is that when i am applyin the strict equality in the code it basically
9+
// gives me the false because the value might be same but the type of both of
10+
//them is definetly diffirent but in the case of the lose equality what we do
11+
//we are having the same value that is hello in both of them
12+
13+
//using symbol primitive value
14+
let g=Symbol("id")
15+
console.log(g)
16+
17+
const k1=Symbol("identifiyers")
18+
const k2=Symbol("something")
19+
myobj={}
20+
myobj[k1]="sagar"
21+
myobj[k2]="singh"
22+
console.log//cloning
23+
(myobj)
24+
console.log(k1==k2)
25+
26+
// immutability from the primitive values
27+
let t="sagar"
28+
let lt=t.toUpperCase()
29+
console.log(lt)
30+
console.log(t)
31+
32+
// objects are mutable
33+
let obj={x:1}
34+
console.log(obj)
35+
obj.x=2
36+
console.log(obj)
37+
obj.x=3
38+
console.log(obj)
39+
40+
// arrays are muatable as well
41+
let arr=[2,3,4,5]
42+
arr[0]=10 // new value added there
43+
console.log(arr)
44+
arr.push(24) // content of the array is also modified
45+
console.log(arr)
46+
47+
//comparision between the object type of values
48+
//over here when we are assigning the value to object in a variable then
49+
//it basically is assigned as a reference to the memory not as the real object itself
50+
51+
let i ={x:2}
52+
let q = {x:2}
53+
console.log(i===q)
54+
55+
arr1=[1,2,3,4,5]
56+
let arr3 = [...arr1]; // Now arr3 is a true copy (shallow)
57+
arr3.push(100);
58+
console.log(arr1); // [1, 2, 3, 4]
59+
console.log(arr3); // [1, 2, 3, 4, 100]
60+
61+
//refernce copy here
62+
ar1=[1,2,3,4,4,6]
63+
ar3=ar1
64+
ar3.push(9)
65+
console.log(ar3)
66+
console.log(ar1)
67+
// we can see that both the array are same when they are printing the same output
68+
// because we are basically making hte changes in the memory location where the
69+
//array was orginally created

0 commit comments

Comments
 (0)