susanahernandezd
4/27/2020 - 6:37 AM

Type guard

/*
  Type of values
  */

// typeof (number, string, boolean, symbol)
if(typeof 4 === 'number') {
  console.log(true);
}

// instanceof (every other value that is created with a constructor function)
if(myArray instanceof Array) {
  console.log(true);
}

if(new Date() instanceof Date) {
  console.log(true);
}

class Person {
  
}
const myPerson = new Person()

if(myPerson instanceof Person) {
  console.log(true);
}