- OBJECTS
- Basics
-
Reference
- Methods
- Constructor
- FUNDAMENTALS
- Hello World
- Code Structure
- Use Strict
- Variables
- Data Types
- Type Conversions
- Maths
- Comparitions
- Conditional
- Loops
- Functions
- TESTING
- Mocha
- Nested Describe
- TYPES
- Primitives
- Numbers
- Strings
- Arrays
- Json
- DESIGN PATTERN
- Observer Pattern
- CLASSES
- Constructor
- Binding
- Inheritance
Reference
A variable assigned to an object stores a reference to it.
/**
* Variable, alwayas copied as value
* Objects, stored by reference
*
* When we copy an object, the resulted two variables ...
* are references to tht same object
*/
let a = "Hello World";
let A = {
'name': 'John',
'age': 30,
}
let x = a; // copy by value
let B = A; // copy by reference
B.name = 'Sam'; // changes reference object
console.log(A === B); // true
console.log(A.name == 'Sam'); // true (copy by reference)
console.log(A.name != 'John'); // true
Equality
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 = {};
let C = B;
console.log(A == B); // false (different objects)
console.log(C === B); // true (reference to the same object)
Last update: 531 days ago