Friday, 21 February 2020

Check Object Equal in JavaScript . How Object reference work in JavaScript

  1. let banana = {};
    • Declare a banana variable.
    • Create a new object value {}.
    • Point banana variable’s wire to it.
  2. let cherry = banana;
    • Declare a cherry variable.
    • Point cherry’s wire to where banana is pointing.
  3. let chocolate = cherry;
    • Then, we declare a chocolate variable.
    • Point chocolate’s wire to where cherry is pointing.
  4. cherry = {};
    • Create a new object value {}.
    • Point cherry’s wire to it.
Now let’s check your answers:
  1. Object.is(banana, cherry) is false because banana and cherry point at different values.
  2. Object.is(cherry, chocolate) is false because cherry and chocolate point at different values.
  3. Object.is(chocolate, banana) is true because chocolate and banana point at the same value.

No comments:

Post a Comment