recursal/MDN huggingface dataset:
Reflect.deleteProperty()
========================

The **`Reflect.deleteProperty()`** static method is like the `delete` operator, but as a function. It deletes a property from an object.

Try it
------

Syntax
------


```js
Reflect.deleteProperty(target, propertyKey)
```

### Parameters

`target`

The target object on which to delete the property.

`propertyKey`

The name of the property to be deleted.

### Return value

A boolean indicating whether or not the property was successfully deleted.

### Exceptions

`TypeError`

Thrown if `target` is not an object.

Description
-----------

`Reflect.deleteProperty()` provides the reflective semantic of the `delete` operator. That is, `Reflect.deleteProperty(target, propertyKey)` is semantically equivalent to:


```js
delete target.propertyKey;
```


At the very low level, deleting a property returns a boolean (as is the case with the proxy handler). `Reflect.deleteProperty()` directly returns the status, while `delete` would throw a `TypeError` in strict mode if the status is `false`. In non-strict mode, `delete` and `Reflect.deleteProperty()` have the same behavior.

`Reflect.deleteProperty()` invokes the `[[Delete]]` object internal method of `target`.

Examples
--------

### Using Reflect.deleteProperty()


```js
const obj = { x: 1, y: 2 };
Reflect.deleteProperty(obj, "x"); // true
console.log(obj); // { y: 2 }

const arr = [1, 2, 3, 4, 5];
Reflect.deleteProperty(arr, "3"); // true
console.log(arr); // [1, 2, 3, undefined, 5]

// Returns true if no such property exists
Reflect.deleteProperty({}, "foo"); // true

// Returns false if a property is unconfigurable
Reflect.deleteProperty(Object.freeze({ foo: 1 }), "foo"); // false
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-reflect.deleteproperty |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `Reflect.deleteProperty` in `core-js`
* `Reflect`
* `delete`
* `handler.deleteProperty()`
Reflect.apply()
===============

The **`Reflect.apply()`** static method calls a target function with arguments as specified.

Try it
------

Syntax
------


```js
Reflect.apply(target, thisArgument, argumentsList)
```

### Parameters

`target`

The target function to call.

`thisArgument`

The value of `this` provided for the call to `target`.

`argumentsList`

An array-like object specifying the arguments with which `target` should be called.

### Return value

The result of calling the given `target` function with the specified `this` value and arguments.

### Exceptions

`TypeError`

Thrown if `target` is not a function or `argumentsList` is not an object.

Description
-----------

`Reflect.apply()` provides the reflective semantic of a function call. That is, `Reflect.apply(target, thisArgument, argumentsList)` is semantically equivalent to:


```js
Math.floor.apply(null, [1.75]);
Reflect.apply(Math.floor, null, [1.75]);
```


The only differences are:

* `Reflect.apply()` takes the function to call as the `target` parameter instead of the `this` context.
* `Reflect.apply()` throws if `argumentsList` is omitted instead of defaulting to calling with no parameters.

`Reflect.apply()` invokes the `[[Call]]` object internal method of `target`.

Examples
--------

### Using Reflect.apply()


```js
Reflect.apply(Math.floor, undefined, [1.75]);
// 1;

Reflect.apply(String.fromCharCode, undefined, [104, 101, 108, 108, 111]);
// "hello"

Reflect.apply(RegExp.prototype.exec, /ab/, ["confabulation"]).index;
// 4

Reflect.apply("".charAt, "ponies", [3]);
// "i"
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-reflect.apply |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `Reflect.apply` in `core-js`
* `Reflect`
* `Function.prototype.apply()`
* `handler.apply()`
Reflect.ownKeys()
=================

The **`Reflect.ownKeys()`** static method returns an array of the `target` object's own property keys.

Try it
------

Syntax
------


```js
Reflect.ownKeys(target)
```

### Parameters

`target`

The target object from which to get the own keys.

### Return value

An `Array` of the `target` object's own property keys, including strings and symbols. For most objects, the array will be in the order of:

1. Non-negative integer indexes in increasing numeric order (but as strings)
2. Other string keys in the order of property creation
3. Symbol keys in the order of property creation.
### Exceptions

`TypeError`

Thrown if `target` is not an object.

Description
-----------

`Reflect.ownKeys()` provides the reflective semantic of retrieving all property keys of an object. It is the only way to get all own properties – enumerable and not enumerable, strings and symbols — in one call, without extra filtering logic. For example, `Object.getOwnPropertyNames()` takes the return value of `Reflect.ownKeys()` and filters to only string values, while `Object.getOwnPropertySymbols()` filters to only symbol values. Because normal objects implement `[[OwnPropertyKeys]]` to return all string keys before symbol keys, `Reflect.ownKeys(target)` is usually equivalent to `Object.getOwnPropertyNames(target).concat(Object.getOwnPropertySymbols(target))`. However, if the object has a custom `[[OwnPropertyKeys]]` method (such as through a proxy's `ownKeys` handler), the order of the keys may be different.

`Reflect.ownKeys()` invokes the `[[OwnPropertyKeys]]` object internal method of `target`.

Examples
--------

### Using Reflect.ownKeys()


```js
Reflect.ownKeys({ z: 3, y: 2, x: 1 }); // [ "z", "y", "x" ]
Reflect.ownKeys([]); // ["length"]

const sym = Symbol.for("comet");
const sym2 = Symbol.for("meteor");
const obj = {
  [sym]: 0,
  str: 0,
  773: 0,
  0: 0,
  [sym2]: 0,
  "-1": 0,
  8: 0,
  "second str": 0,
};
Reflect.ownKeys(obj);
// [ "0", "8", "773", "str", "-1", "second str", Symbol(comet), Symbol(meteor) ]
// Indexes in numeric order,
// strings in insertion order,
// symbols in insertion order
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-reflect.ownkeys |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `Reflect.ownKeys` in `core-js`
* `Reflect`
* `Object.getOwnPropertyNames()`
* `Object.getOwnPropertySymbols()`
* `handler.ownKeys()`
Reflect.set()
=============

The **`Reflect.set()`** static method is like the property accessor and assignment syntax, but as a function.

Try it
------

Syntax
------


```js
Reflect.set(target, propertyKey, value)
Reflect.set(target, propertyKey, value, receiver)
```

### Parameters

`target`

The target object on which to set the property.

`propertyKey`

The name of the property to set.

`value`

The value to set.

`receiver` Optional

The value of `this` provided for the call to the setter for `propertyKey` on `target`. If provided and `target` does not have a setter for `propertyKey`, the property will be set on `receiver` instead.

### Return value

A `Boolean` indicating whether or not setting the property was successful.

### Exceptions

`TypeError`

Thrown if `target` is not an object.

Description
-----------

`Reflect.set()` provides the reflective semantic of a property access. That is, `Reflect.set(target, propertyKey, value, receiver)` is semantically equivalent to:


```js
target[propertyKey] = value;
```


Note that in a normal property access, `target` and `receiver` would observably be the same object.

`Reflect.set()` invokes the `[[Set]]` object internal method of `target`.

Examples
--------

### Using Reflect.set()


```js
// Object
const obj = {};
Reflect.set(obj, "prop", "value"); // true
obj.prop; // "value"

// Array
const arr = ["duck", "duck", "duck"];
Reflect.set(arr, 2, "goose"); // true
arr[2]; // "goose"

// It can truncate an array.
Reflect.set(arr, "length", 1); // true
arr; // ["duck"]

// With just one argument, propertyKey and value are "undefined".
Reflect.set(obj); // true
Reflect.getOwnPropertyDescriptor(obj, "undefined");
// { value: undefined, writable: true, enumerable: true, configurable: true }
```

### Different target and receiver

When the `target` and `receiver` are different, `Reflect.set` will use the property descriptor of `target` (to find the setter or determine if the property is writable), but set the property on `receiver`.


```js
const target = {};
const receiver = {};
Reflect.set(target, "a", 2, receiver); // true
// target is {}; receiver is { a: 2 }

const target = { a: 1 };
const receiver = {};
Reflect.set(target, "a", 2, receiver); // true
// target is { a: 1 }; receiver is { a: 2 }

const target = {
  set a(v) {
    this.b = v;
  },
};
const receiver = {};
Reflect.set(target, "a", 2, receiver); // true
// target is { a: [Setter] }; receiver is { b: 2 }
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-reflect.set |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `Reflect.set` in `core-js`
* `Reflect`
* Property accessors
* `handler.set()`
Reflect.defineProperty()
========================

The **`Reflect.defineProperty()`** static method is like `Object.defineProperty()` but returns a `Boolean`.

Try it
------

Syntax
------


```js
Reflect.defineProperty(target, propertyKey, attributes)
```

### Parameters

`target`

The target object on which to define the property.

`propertyKey`

The name of the property to be defined or modified.

`attributes`

The attributes for the property being defined or modified.

### Return value

A boolean indicating whether or not the property was successfully defined.

### Exceptions

`TypeError`

Thrown if `target` or `attributes` is not an object.

Description
-----------

`Reflect.defineProperty()` provides the reflective semantic of defining an own property on an object. At the very low level, defining a property returns a boolean (as is the case with the proxy handler). `Object.defineProperty()` provides nearly the same semantic, but it throws a `TypeError` if the status is `false` (the operation was unsuccessful), while `Reflect.defineProperty()` directly returns the status.

Many built-in operations would also define own properties on objects. The most significant difference between defining properties and setting them is that setters aren't invoked. For example, class fields directly define properties on the instance without invoking setters.


```js
class B extends class A {
  set a(v) {
    console.log("Setter called");
  }
} {
  a = 1; // Nothing logged
}
```


`Reflect.defineProperty()` invokes the `[[DefineOwnProperty]]` object internal method of `target`.

Examples
--------

### Using Reflect.defineProperty()


```js
const obj = {};
Reflect.defineProperty(obj, "x", { value: 7 }); // true
console.log(obj.x); // 7
```

### Checking if property definition has been successful

With `Object.defineProperty()`, which returns an object if successful, or throws a `TypeError` otherwise, you would use a `try...catch` block to catch any error that occurred while defining a property.

Because `Reflect.defineProperty()` returns a Boolean success status, you can just use an `if...else` block here:


```js
if (Reflect.defineProperty(target, property, attributes)) {
  // success
} else {
  // failure
}
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-reflect.defineproperty |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `Reflect.defineProperty` in `core-js`
* `Reflect`
* `Object.defineProperty()`
* `handler.defineProperty()`
Reflect.getOwnPropertyDescriptor()
==================================

The **`Reflect.getOwnPropertyDescriptor()`** static method is like `Object.getOwnPropertyDescriptor()`. It returns a property descriptor of the given property if it exists on the object, `undefined` otherwise.

Try it
------

Syntax
------


```js
Reflect.getOwnPropertyDescriptor(target, propertyKey)
```

### Parameters

`target`

The target object in which to look for the property.

`propertyKey`

The name of the property to get an own property descriptor for.

### Return value

A property descriptor object if the property exists as an own property of `target`; otherwise, `undefined`.

### Exceptions

`TypeError`

Thrown if `target` is not an object.

Description
-----------

`Reflect.getOwnPropertyDescriptor()` provides the reflective semantic of retrieving the property descriptor of an object. The only difference with `Object.getOwnPropertyDescriptor()` is how non-object targets are handled. `Reflect.getOwnPropertyDescriptor()` throws a `TypeError` if the target is not an object, while `Object.getOwnPropertyDescriptor()` coerces it to an object.

`Reflect.getOwnPropertyDescriptor()` invokes the `[[GetOwnProperty]]` object internal method of `target`.

Examples
--------

### Using Reflect.getOwnPropertyDescriptor()


```js
Reflect.getOwnPropertyDescriptor({ x: "hello" }, "x");
// {value: "hello", writable: true, enumerable: true, configurable: true}

Reflect.getOwnPropertyDescriptor({ x: "hello" }, "y");
// undefined

Reflect.getOwnPropertyDescriptor([], "length");
// {value: 0, writable: true, enumerable: false, configurable: false}
```

### Difference with Object.getOwnPropertyDescriptor()

If the `target` argument to this method is not an object (a primitive), then it will cause a `TypeError`. With `Object.getOwnPropertyDescriptor`, a non-object first argument will be coerced to an object at first.


```js
Reflect.getOwnPropertyDescriptor("foo", 0);
// TypeError: "foo" is not non-null object

Object.getOwnPropertyDescriptor("foo", 0);
// { value: "f", writable: false, enumerable: true, configurable: false }
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-reflect.getownpropertydescriptor |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `Reflect.getOwnPropertyDescriptor` in `core-js`
* `Reflect`
* `Object.getOwnPropertyDescriptor()`
* `handler.getOwnPropertyDescriptor()`
Reflect.setPrototypeOf()
========================

The **`Reflect.setPrototypeOf()`** static method is like `Object.setPrototypeOf()` but returns a `Boolean`. It sets the prototype (i.e., the internal `[[Prototype]]` property) of a specified object.

Try it
------

Syntax
------


```js
Reflect.setPrototypeOf(target, prototype)
```

### Parameters

`target`

The target object of which to set the prototype.

`prototype`

The object's new prototype (an object or `null`).

### Return value

A `Boolean` indicating whether or not the prototype was successfully set.

### Exceptions

`TypeError`

Thrown if `target` is not an object or if `prototype` is neither an object nor `null`.

Description
-----------

`Reflect.setPrototypeOf()` provides the reflective semantic of setting the prototype of an object. At the very low level, setting the prototype returns a boolean (as is the case with the proxy handler). `Object.setPrototypeOf()` provides nearly the same semantic, but it throws a `TypeError` if the status is `false` (the operation was unsuccessful), while `Reflect.setPrototypeOf()` directly returns the status.

`Reflect.setPrototypeOf()` invokes the `[[SetPrototypeOf]]` object internal method of `target`.

Examples
--------

### Using Reflect.setPrototypeOf()


```js
Reflect.setPrototypeOf({}, Object.prototype); // true

// It can change an object's [[Prototype]] to null.
Reflect.setPrototypeOf({}, null); // true

// Returns false if target is not extensible.
Reflect.setPrototypeOf(Object.freeze({}), null); // false

// Returns false if it cause a prototype chain cycle.
const target = {};
const proto = Object.create(target);
Reflect.setPrototypeOf(target, proto); // false
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-reflect.setprototypeof |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `Reflect.setPrototypeOf` in `core-js`
* `Reflect`
* `Object.setPrototypeOf()`
* `handler.setPrototypeOf()`
Reflect.has()
=============

 The **`Reflect.has()`** static method is like the `in` operator, but
 as a function.

Try it
------

Syntax
------


```js
Reflect.has(target, propertyKey)
```

### Parameters

`target`

The target object in which to look for the property.

`propertyKey`

The name of the property to check.

### Return value

A `Boolean` indicating whether or not the `target` has the property.

### Exceptions

`TypeError`

Thrown if `target` is not an object.

Description
-----------

`Reflect.has()` provides the reflective semantic of checking if a property is in an object. That is, `Reflect.has(target, propertyKey)` is semantically equivalent to:


```js
propertyKey in target;
```


`Reflect.has()` invokes the `[[HasProperty]]` object internal method of `target`.

Examples
--------

### Using Reflect.has()


```js
Reflect.has({ x: 0 }, "x"); // true
Reflect.has({ x: 0 }, "y"); // false

// returns true for properties in the prototype chain
Reflect.has({ x: 0 }, "toString");

// Proxy with .has() handler method
obj = new Proxy(
  {},
  {
    has(t, k) {
      return k.startsWith("door");
    },
  },
);
Reflect.has(obj, "doorbell"); // true
Reflect.has(obj, "dormitory"); // false
```


`Reflect.has` returns `true` for any inherited properties, like the `in` operator:


```js
const a = { foo: 123 };
const b = { \_\_proto\_\_: a };
const c = { \_\_proto\_\_: b };
// The prototype chain is: c -> b -> a
Reflect.has(c, "foo"); // true
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-reflect.has |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `Reflect.has` in `core-js`
* `Reflect`
* `in`
* `handler.has()`
Reflect.get()
=============

The **`Reflect.get()`** static method is like the property accessor syntax, but as a function.

Try it
------

Syntax
------


```js
Reflect.get(target, propertyKey)
Reflect.get(target, propertyKey, receiver)
```

### Parameters

`target`

The target object on which to get the property.

`propertyKey`

The name of the property to get.

`receiver` Optional

The value of `this` provided for the call to `target` if a getter is encountered.

### Return value

The value of the property.

### Exceptions

`TypeError`

Thrown if `target` is not an object.

Description
-----------

`Reflect.get()` provides the reflective semantic of a property access. That is, `Reflect.get(target, propertyKey, receiver)` is semantically equivalent to:


```js
target[propertyKey];
```


Note that in a normal property access, `target` and `receiver` would observably be the same object.

`Reflect.get()` invokes the `[[Get]]` object internal method of `target`.

Examples
--------

### Using Reflect.get()


```js
// Object
const obj1 = { x: 1, y: 2 };
Reflect.get(obj1, "x"); // 1

// Array
Reflect.get(["zero", "one"], 1); // "one"

// Proxy with a get handler
const obj2 = new Proxy(
  { p: 1 },
  {
    get(t, k, r) {
      return k + "bar";
    },
  },
);
Reflect.get(obj2, "foo"); // "foobar"

// Proxy with get handler and receiver
const obj3 = new Proxy(
  { p: 1, foo: 2 },
  {
    get(t, prop, receiver) {
      return receiver[prop] + "bar";
    },
  },
);
Reflect.get(obj3, "foo", { foo: 3 }); // "3bar"
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-reflect.get |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `Reflect.get` in `core-js`
* `Reflect`
* Property accessors
* `handler.get()`
Reflect.isExtensible()
======================

The **`Reflect.isExtensible()`** static method is like `Object.isExtensible()`. It determines if an object is extensible (whether it can have new properties added to it).

Try it
------

Syntax
------


```js
Reflect.isExtensible(target)
```

### Parameters

`target`

The target object which to check if it is extensible.

### Return value

A `Boolean` indicating whether or not the target is extensible.

### Exceptions

`TypeError`

Thrown if `target` is not an object.

Description
-----------

`Reflect.isExtensible()` provides the reflective semantic of checking if an object is extensible. The only difference with `Object.isExtensible()` is how non-object targets are handled. `Reflect.isExtensible()` throws a `TypeError` if the target is not an object, while `Object.isExtensible()` always returns `false` for non-object targets.

`Reflect.isExtensible()` invokes the `[[IsExtensible]]` object internal method of `target`.

Examples
--------

### Using Reflect.isExtensible()

See also `Object.isExtensible()`.


```js
// New objects are extensible.
const empty = {};
Reflect.isExtensible(empty); // true

// ...but that can be changed.
Reflect.preventExtensions(empty);
Reflect.isExtensible(empty); // false

// Sealed objects are by definition non-extensible.
const sealed = Object.seal({});
Reflect.isExtensible(sealed); // false

// Frozen objects are also by definition non-extensible.
const frozen = Object.freeze({});
Reflect.isExtensible(frozen); // false
```

### Difference with Object.isExtensible()

If the `target` argument to this method is not an object (a primitive), then it will cause a `TypeError`. With `Object.isExtensible()`, a non-object `target` will return false without any errors.


```js
Reflect.isExtensible(1);
// TypeError: 1 is not an object

Object.isExtensible(1);
// false
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-reflect.isextensible |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `Reflect.isExtensible` in `core-js`
* `Reflect`
* `Object.isExtensible()`
* `handler.isExtensible()`