Skip to content

Instantly share code, notes, and snippets.

@hoyangtsai
Created April 17, 2022 07:12
Show Gist options
  • Save hoyangtsai/a26ad144451b372e7cf51390643b19d6 to your computer and use it in GitHub Desktop.
Save hoyangtsai/a26ad144451b372e7cf51390643b19d6 to your computer and use it in GitHub Desktop.
#js instanceof check
function Product(name, price) {
this.name = name;
this.price = price;
}
function Food(name, price) {
Product.call(this, name, price);
this.category = 'food';
}
const cheese = new Food('cheese', 12);
console.log(cheese instanceof Product) // false
console.log(cheese instanceof Food) // true
// ----
console.log(123 instanceof Number) // false
console.log(new Number(123) instanceof Number) // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment