HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
🧐
Sonny
/
🧐
in 연산자와 hasOwn 메서드의 차이
🧐

in 연산자와 hasOwn 메서드의 차이

상태
해결
작성일
Apr 11, 2024
태그
Personal

History

  • 사프 팀원분이 in 연산자가 아닌 hasOwn() 메서드를 쓰는게 어떠신지 의견을 남겨주셨다.

Result

  • hasOwn() 메서드는 객체가 직접 소유하고 있는 프로퍼티만 확인한다. (프로토타입 체인을 통해 상속된 속성은 포함 X)
  • in연산자는 객체의 프로토타입 체인 전체를 확인하여 상속받은 속성도 true로 판별한다.

Reference

Object.hasOwn() - JavaScript | MDN
The Object.hasOwn() static method returns true if the specified object has the indicated property as its own property. If the property is inherited, or does not exist, the method returns false.
Object.hasOwn() - JavaScript | MDN
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn
Object.hasOwn() - JavaScript | MDN