🟨 JavaScript/κ°œλ…

[mdn, λ“œλ¦Όμ½”λ”© μ™Έ] 객체지ν–₯ (5) : instanceOf μ—°μ‚°μž

Zoeeey 2022. 5. 25. 14:07

instanceOf μ—°μ‚°μž(operator)

instanceOf μ—°μ‚°μžλŠ” μƒμ„±μžμ˜ ν”„λ‘œν† νƒ€μž… 속성이 객체의 ν”„λ‘œν† νƒ€μž… 체인에 μ‘΄μž¬ν•˜λŠ”μ§€ νŒλ³„ν•˜μ—¬ true λ‚˜ falseλ₯Ό λ±‰λŠ”λ‹€.

class Goodcoder {
  constructor(age, lang, address) {
    this.age = age;
    this.lang = lang;
    this.address = address;
  }
}

const noran = new Goodcoder(20,'Java','Seoul');


console.log(noran instanceof Goodcoder); //true
console.log(paran instanceof Goodcoder); //Uncaught ReferenceError: paran is not defined

좜처 : λ“œλ¦Όμ½”λ”© https://www.youtube.com/@dream-coding / MDN https://developer.mozilla.org/ko