Xah Talk Show 2026-01-17 Ep745 JavaScript in Depth. hasOwnProperty vs Object.hasOwn
Video Summary (Generated by AI, Edited by Human.)
The video is a deep dive into JavaScript by Xah Lee, focusing on the nuances of the language, particularly the hasOwnProperty method versus the newer Object.hasOwn (0:41).
Here's a summary of the key points:
Xah Lee's JavaScript Tutorial (0:41): The speaker introduces his "JavaScript in Depth" tutorial, claiming it to be the most comprehensive, concise, and in-depth JavaScript tutorial available. He mentions it has about 600 pages focusing on JavaScript, with an additional "JavaScript Object Reference" that he admits is missing some modern features like TypedArray, BigInt, Intl (internationalization features), Proxy, and Promise (2:01). He also notes that Iterator is extremely complex and fully detailed in his tutorial (2:57).
Challenges and Flaws in JavaScript (5:08): Xah Lee heavily criticizes JavaScript's design, attributing many of its issues to its rushed creation in 10 days in 1995.
Array Design (5:08): He calls array design "badly designed" and a "major problem" that "destroyed JavaScript language." He highlights the concept of "array-like objects" (5:56) which causes significant issues and cannot be fixed due to backward compatibility for the internet's 30-year history.
Sparse Arrays (7:04): Another major flaw is the "sparse array" where items might appear to have a length but don't actually exist at certain indices, leading to unexpected behavior with functions like map (7:53). He notes the difference between an empty item and an item with an undefined value (8:22).
hasOwnProperty vs. Object.hasOwn (10:45): The core of the coding session revolves around these two methods.
Object.prototype.hasOwnProperty (10:47): This method checks if an object has a property as its own property, not an inherited one (11:06). The complexity arises because hasOwnProperty is a property of Object.prototype, and calling it on an object (e.g., xx.hasOwnProperty) involves JavaScript's prototype inheritance system, where it looks up the parent chain if the property is not directly on the object (29:08).
The Problem with hasOwnProperty (36:00): The main issue demonstrated is that if an object itself has a property named hasOwnProperty (overriding the inherited method), it can lead to unexpected results, as the custom property will be invoked instead of the built-in function (40:01). This can break the intended behavior of checking for own properties.
Introduction of Object.hasOwn (43:06): To address this problem, Object.hasOwn was introduced in 2022 (three years prior to the video's context, implying the video was recorded in 2025 based on the speaker's time reference (44:12)). This new function does not rely on the prototype chain, making it a more reliable way to check for own properties (42:52).
General Critique of Popular Languages (47:50): Xah Lee states that the top five most popular programming languages (C, C++, JavaScript, Python, PHP) are "the worst f*cking possible" (47:54). He explains his deep dive into JavaScript is because it's unavoidable for web development, which is his job (49:46).
Recommended JavaScript Resources (50:50): He recommends a few JavaScript books and authors that he considers excellent:
David Flanagan's "JavaScript: The Definitive Guide" (51:23) Douglas Crockford (52:45), though he hasn't read his latest book. Dr. Axel Rauschmayer's "Exploring JavaScript" (54:48)
He criticizes Mozilla's MDN JavaScript tutorials as "misleading crap" (58:46) for beginners, though he acknowledges MDN is the best source for the latest browser support and JavaScript specifications (59:15).
// way to list all properties of a thing Reflect.ownKeys(Object); /* [ "length", "name", "prototype", "assign", "getOwnPropertyDescriptor", "getOwnPropertyDescriptors", "getOwnPropertyNames", "getOwnPropertySymbols", "hasOwn", "is", "preventExtensions", "seal", "create", "defineProperties", "defineProperty", "freeze", "getPrototypeOf", "setPrototypeOf", "isExtensible", "isFrozen", "isSealed", "keys", "entries", "fromEntries", "values", "groupBy" ] */ // s------------------------------ // 2 common ways to access a property Object.prototype; Object["prototype"]; // s------------------------------ /* a property, is key and value pair key can be string type or symbol type object, in js, is defined to be a collection of key value pairs. such is called a property. but in fact, in js, many object have special things besides just a collection of key values, such as function, date, regex. */ // s------------------------------ Reflect.ownKeys(Object.prototype); /* [ "constructor", "__defineGetter__", "__defineSetter__", "hasOwnProperty", "__lookupGetter__", "__lookupSetter__", "isPrototypeOf", "propertyIsEnumerable", "toString", "valueOf", "toLocaleString" ] */ // s------------------------------ // how to find the parent of a object console.log(Reflect.getPrototypeOf({ "p": 1 }) === Object.prototype); // true
const xdad = { "hasOwnProperty": function () { return "haha u faaked"; }, }; const xson = { "toy": "train" }; Reflect.setPrototypeOf(xson, xdad); console.log(Reflect.getPrototypeOf(xson) === xdad); // true console.log(xson.hasOwnProperty("toy")); // haha u faaked console.log(Object.hasOwn(xson, "toy")); // true