@@ -3,7 +3,26 @@ let x = [1,2,3];
33let y = [ 1 , 2 , 3 ] ;
44let z = y ;
55
6- function compare ( a , b ) {
6+ x == y ? console . log ( "equal" ) : console . log ( "not equal" ) ;
7+ x === y ? console . log ( "equal" ) : console . log ( "not equal" ) ;
8+ z == x ? console . log ( "equal" ) : console . log ( "not equal" ) ;
9+ z === x ? console . log ( "equal" ) : console . log ( "not equal" ) ;
10+ z == y ? console . log ( "equal" ) : console . log ( "not equal" ) ;
11+ z === y ? console . log ( "equal" ) : console . log ( "not equal" ) ;
12+ /*Why is these equal/not equal? because x and y might have the same looking info in it, they are not the same objects.
13+ but z and y do have the same objects, because they are both just pointers pointing to the same box.
14+ x and y are both pointing to two different boxes which both happen to have the same info in it.*/
15+
16+
17+ /*assigning variable by content or reference , ie z = y is saying that z has the same 'address' as y does.//
18+ ie they both point to the same box, with the box being the [] stuff
19+ note: x does not equal y in this case because they do not point to the same object.
20+ ie: their objects look the same, but they are two different boxes, whilst z is only pointing to y's box,
21+ it is not actually making a whole new box for z */
22+ /*THIS CODE DOESN'T OUTPUT THE RIGHT INFO. THE LAST SHOULD BE FALSE */
23+
24+
25+ /*function compare(a, b) {
726 var i = a.length;
827 if (i != b.length) return false;
928 while (i--) {
@@ -13,7 +32,7 @@ function compare(a, b) {
1332}
1433console.log(compare(x, y));
1534console.log(compare(z, y));
16- console . log ( compare ( z , x ) ) ;
35+ console.log(compare(z, x));*/
1736
1837
1938
@@ -28,6 +47,8 @@ console.log(o3);
2847o2 . foo = 'chicken' ;
2948console . log ( o2 ) ;
3049console . log ( o3 ) ; // yes o3 has been changed//
50+ /* this is the same as question 15, o2 and o3 both point to the same box. so when you change the box
51+ contents, both o2 and o3 change because they are both pointing to that box.*/ node
3152
3253// 17. type of//
3354let bar = 42 ;
0 commit comments