Object.preventExtensions — blocking new properties
Object.preventExtensions(obj) irreversibly blocks adding own properties to an object and returns that same object. It does not freeze existing values or nested objects.
CKTIS / JavaScript
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
Object.preventExtensions(obj) irreversibly blocks adding own properties to an object and returns that same object. It does not freeze existing values or nested objects.
Object.prototype.constructor is a data property whose initial value is the Object function. Objects usually inherit constructor from a prototype, but it can be shadowed, so it is not a reliable way to identify a type.
Object.prototype.hasOwnProperty() checks whether a property belongs directly to an object rather than its prototype. Learn how it differs from in and how to call it safely when the method is shadowed.
Object.seal prevents adding and deleting an object's own properties without making the object immutable. On ordinary objects, existing writable data properties can still receive new values, and nested objects are not automatically sealed.
For an ordinary object, a successful `Object.setPrototypeOf(obj, proto)` call sets its internal prototype without copying properties and returns the same object. `proto` must be an object or `null`. A `Proxy` with an extensible target can report success through its `setPrototypeOf` trap without changing the target's prototype. The call still returns the original `Proxy`.
Object.values(obj) returns a new array of values from own, enumerable, string-keyed properties. It excludes inherited properties, non-enumerable properties, and Symbol keys.
Promise.all returns a single promise for all elements of an iterable. If iteration completes without error and all elements yield values, the promise fulfills with an array of results in input order. The first observed input rejection rejects the combined promise. An exception thrown during iteration can also reject it, even if no input promise rejects. The method does not cancel the remaining operations.
Promise.allSettled accepts an iterable and returns a promise for an array of all element outcomes. It preserves input order and records both fulfilled values and rejection reasons.
Promise.any accepts an iterable and returns a promise fulfilled with the value of the first fulfillment it observes. Input rejections do not end the wait unless every input rejects; in that case, the result rejects with AggregateError.
The catch() method attaches a promise rejection handler. It lets you recover with a successful value or propagate a failure and, with the standard then method, returns a new promise.
Promise.prototype.finally runs a callback after a promise fulfills or rejects. It provides shared cleanup that normally preserves the original outcome, although a cleanup failure can replace that outcome.
Promise.prototype.then registers fulfillment or rejection handlers and returns a new promise. The handler's result determines how the chain continues.
Promise.race(iterable) returns a promise that adopts the fulfillment value or rejection reason from the first settlement processed. It does not wait for the first success and does not cancel the remaining operations.
Promise.reject(reason) creates a new rejected promise with the supplied reason. Rejection handlers run asynchronously even though the returned promise is already rejected.
Promise.resolve(value) lets you treat an ordinary value, a promise, or a thenable as a promise. It can return an existing promise unchanged; resolved does not mean that the result is already available or that the operation will succeed.
Promise.withResolvers() returns a new promise and its associated resolve and reject functions. It separates creating a promise from supplying its outcome, for example when adapting a callback-based interface.
Proxy creates an object that mediates operations on a target object. The handler.get and handler.set methods let you compute values when reading and control writes while respecting language invariants.
RangeError is a built-in ECMAScript error type indicating a value outside an allowed set or range. Use it to signal invalid arguments and handle such exceptions with try...catch.
ReferenceError is a built-in JavaScript error type thrown, among other cases, when reading an unresolved name or a variable before initialization. Learn how a missing variable differs from undefined and why typeof does not bypass initialization rules.
Reflect.apply calls a function with a supplied `this` value and arguments read from a supplied object. It returns the function's result without reading the function's `apply` property.
Reflect.construct invokes a constructor with arguments read from an object. Its optional newTarget separates the constructor being executed from the new.target value and the usual prototype selection.
Reflect.defineProperty defines or changes an object's own property using a descriptor. It returns true or false, but does not guarantee exception-free execution.
Reflect.deleteProperty(target, propertyKey) attempts to delete an object's own property and returns a boolean result. For an ordinary object, it returns true even when the property is absent, and false when the property has configurable: false.
`Reflect.get` reads an object's property, including an inherited one. In ordinary lookup, the receiver is passed as the getter's `this` argument without changing where lookup begins.