Fundamentals 12 min read

Understanding ECMAScript Specification: Object.prototype.hasOwnProperty and Abstract Operations

This article walks through a concrete example of Object.prototype.hasOwnProperty in the ECMAScript specification, explaining language and specification types, abstract operations, internal slots and methods, Completion Records, and the shorthand ? and ! used for error handling in spec algorithms.

ByteFE
ByteFE
ByteFE
Understanding ECMAScript Specification: Object.prototype.hasOwnProperty and Abstract Operations

Preface

Even if you know JavaScript, reading its language specification, the ECMAScript Language Specification (ECMAScript spec), can be daunting. We start with a concrete example to walk through the spec and understand the notation.

The following code demonstrates usage of Object.prototype.hasOwnProperty :

const o = { foo: 1 };
 o.hasOwnProperty('foo'); // true
 o.hasOwnProperty('bar'); // false

In the example, o does not have its own hasOwnProperty property, so the prototype chain is consulted and the method is found on Object.prototype .

To describe how Object.prototype.hasOwnProperty works, the spec uses pseudocode‑like descriptions:

Object.prototype.hasOwnProperty(V) When the hasOwnProperty method is called with argument V , the following steps are taken: 1. Let P be ? ToPropertyKey(V) . 2. Let O be ? ToObject(this value) . 3. Return ? HasOwnProperty(O, P) .

…and…

HasOwnProperty(O, P) The abstract operation HasOwnProperty determines whether an object has an own property with the specified key. It asserts that Type(O) is Object and that IsPropertyKey(P) is true, then performs the steps to retrieve the property descriptor and return a Boolean wrapped in a Completion Record.

Language Types and Specification Types

The spec distinguishes between language values (e.g., undefined , true , false ) which are part of JavaScript, and specification types that exist only in the spec (e.g., Record , Completion Record ). Engines may implement specification types internally, but they are not required to expose them to JavaScript code.

Abstract Operations

Abstract operations are functions defined in the ECMAScript spec to write algorithms concisely. They are not callable from JavaScript and do not need to be implemented as separate runtime functions.

Internal Slots and Internal Methods

Internal slots (e.g., [[Prototype]] ) are data members used by the engine to store object state, while internal methods (e.g., [[GetOwnProperty]] ) are functions that operate on those slots. They are not accessible from JavaScript code.

Completion Records

Every abstract operation implicitly returns a Completion Record, which contains a [[Type]] (e.g., normal ) and a [[Value]] . The spec uses the shorthand ? to mean “if the result is an abrupt completion, return it; otherwise extract [[Value]] .” The exclamation mark ! asserts that a value is not an abrupt completion.

ReturnIfAbrupt

ReturnIfAbrupt(argument) checks whether argument is an abrupt completion; if so, it returns it, otherwise it extracts argument.[[Value]] .

Side Track: Return ? Foo()

The notation expands to:

1. Let temp be Foo() . 2. If temp is an abrupt completion, return temp . 3. Set temp to temp.[[Value]] . 4. Return NormalCompletion(temp) .

Asserts

Asserts in the spec state invariant conditions for clarity; implementations are not required to perform these checks.

Summary

We examined the Object.prototype.hasOwnProperty method and the abstract operations it invokes, learning the meaning of the ? and ! shorthands for error handling, as well as language types, specification types, internal slots, and internal methods.

Useful Links

How to Read the ECMAScript Specification : a tutorial covering much of the material discussed.

JavaScriptECMAScriptSpecificationAbstract OperationshasOwnProperty
ByteFE
Written by

ByteFE

Cutting‑edge tech, article sharing, and practical insights from the ByteDance frontend team.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.