links: YDK JS Chapter 2


There are two types of equality

  1. Structural Equality
  2. Reference Equality

Structural Equality

Structural equality asks if two references are the same value


let x = 10

let y = 2 * 5

console.log(x == y)

The above prints true as both the values are equal

Reference Equality

Reference Equality asks if two reference addresses are same

let x = {name: "Subramanya"}
let y = x

console.log(x === y) // true

The above one prints true because both x and y point to same reference

where as

let x = {name: "Subramanya"}
let y = {name: "Subramanya"}

console.log(x === y) // false

this will print false as both the references (address) of objects are different


tags: fundamentals

source