Javascript
/
Objects
- 1 Fundamentals 11
-
Hello World
-
Code structure
-
Use strict
-
Variables
-
Data types
-
Type conversions
-
Maths
-
Comparitions
-
Conditional
-
Loops
-
Functions
- 2 Testing 2
-
Mocha
-
Nested describe
- 3 Objects 4
-
Basics
-
Reference
-
Methods
-
Constructor
- 4 Types 5
-
Primitives
-
Numbers
-
Strings
-
Arrays
-
Json
- 5 Classes 3
-
Constructor
-
Binding
-
Inheritance
/
Reference
➟
➟
Last update: 25-01-2022
Reference
A variable assigned to an object stores a reference to it.
/**
* In Javascript a variable is alwayas copied as value.
*
* Objects are different, they are stored by reference.
*
* When we copy an object, the resulted two variables are ...
* references to tht same object (that address in computer memory).
*/
let a = "Hello World";
let b = a;
console.log(a === b); // true
let c = {
'name': 'John',
'age': 30,
}
let d = c;
d.name = 'Sam';
console.log(c.name); // Sam (not John) - Look Here
Comparing
Two objects are equal only if they are the same object.
/**
* Two independent objects are not equal ...
* even thought they look alike.
*/
let a = {};
let b = {};
console.log(a == b); // different objects
// false
let c = {};
let d = c;
console.log(c === d); // reference to the same object
// true
➥ Questions github Objects