recursal/MDN huggingface dataset:
Boolean.prototype.valueOf()
===========================

 The **`valueOf()`** method of `Boolean` values returns the primitive value of a
 `Boolean` object.

Try it
------

Syntax
------


```js
valueOf()
```

### Parameters

None.

### Return value

The primitive value of the given `Boolean` object.

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

 The `valueOf()` method of `Boolean` returns the primitive value
 of a `Boolean` object or literal `Boolean` as a Boolean data type.

This method is usually called internally by JavaScript and not explicitly in code.

Examples
--------

### Using `valueOf()`


```js
x = new Boolean();
myVar = x.valueOf(); // assigns false to myVar
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-boolean.prototype.valueof |

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

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

See also
--------

* `Object.prototype.valueOf()`
Object.isExtensible()
=====================

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

Try it
------

Syntax
------


```js
Object.isExtensible(obj)
```

### Parameters

`obj`

The object which should be checked.

### Return value

A `Boolean` indicating whether or not the given object is extensible.

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

Objects are extensible by default: they can have new properties added to them, and their `[[Prototype]]` can be re-assigned. An object can be marked as non-extensible using one of `Object.preventExtensions()`, `Object.seal()`, `Object.freeze()`, or `Reflect.preventExtensions()`.

Examples
--------

### Using Object.isExtensible


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

// They can be made un-extensible
Object.preventExtensions(empty);
Object.isExtensible(empty); // false

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

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

### Non-object argument

In ES5, if the argument to this method is not an object (a primitive), then it will cause a `TypeError`. In ES2015, it will return `false` without any errors if a non-object argument is passed, since primitives are, by definition, immutable.


```js
Object.isExtensible(1);
// TypeError: 1 is not an object (ES5 code)

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

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

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

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

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

See also
--------

* `Object.preventExtensions()`
* `Object.seal()`
* `Object.isSealed()`
* `Object.freeze()`
* `Object.isFrozen()`
* `Reflect.isExtensible()`
Object.fromEntries()
====================

The **`Object.fromEntries()`** static method transforms a list of key-value pairs into an object.

Try it
------

Syntax
------


```js
Object.fromEntries(iterable)
```

### Parameters

`iterable`

An iterable, such as an `Array` or `Map`, containing a list of objects. Each object should have two properties:

`0`

A string or symbol representing the property key.

`1`

The property value.

Typically, this object is implemented as a two-element array, with the first element being the property key and the second element being the property value.

### Return value

A new object whose properties are given by the entries of the iterable.

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

The `Object.fromEntries()` method takes a list of key-value pairs and returns a new object whose properties are given by those entries. The `iterable` argument is expected to be an object that implements an `@@iterator` method. The method returns an iterator object that produces two-element array-like objects. The first element is a value that will be used as a property key, and the second element is the value to associate with that property key.

`Object.fromEntries()` performs the reverse of `Object.entries()`, except that `Object.entries()` only returns string-keyed properties, while `Object.fromEntries()` can also create symbol-keyed properties.

**Note:** Unlike `Array.from()`, `Object.fromEntries()` does not use the value of `this`, so calling it on another constructor does not create objects of that type.

Examples
--------

### Converting a Map to an Object

With `Object.fromEntries`, you can convert from `Map` to `Object`:


```js
const map = new Map([
  ["foo", "bar"],
  ["baz", 42],
]);
const obj = Object.fromEntries(map);
console.log(obj); // { foo: "bar", baz: 42 }
```

### Converting an Array to an Object

With `Object.fromEntries`, you can convert from `Array` to `Object`:


```js
const arr = [
  ["0", "a"],
  ["1", "b"],
  ["2", "c"],
];
const obj = Object.fromEntries(arr);
console.log(obj); // { 0: "a", 1: "b", 2: "c" }
```

### Object transformations

With `Object.fromEntries`, its reverse method `Object.entries()`, and array manipulation methods, you are able to transform objects like this:


```js
const object1 = { a: 1, b: 2, c: 3 };

const object2 = Object.fromEntries(
  Object.entries(object1).map(([key, val]) => [key, val \* 2]),
);

console.log(object2);
// { a: 2, b: 4, c: 6 }
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-object.fromentries |

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

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

See also
--------

* Polyfill of `Object.fromEntries` in `core-js`
* `Object.entries()`
* `Object.keys()`
* `Object.values()`
* `Object.prototype.propertyIsEnumerable()`
* `Object.create()`
* `Map.prototype.entries()`
* `Map.prototype.keys()`
* `Map.prototype.values()`
Object.getOwnPropertyDescriptors()
==================================

 The **`Object.getOwnPropertyDescriptors()`** static method returns all
 own property descriptors of a given object.

Try it
------

Syntax
------


```js
Object.getOwnPropertyDescriptors(obj)
```

### Parameters

`obj`

The object for which to get all own property descriptors.

### Return value

 An object containing all own property descriptors of an object. Might be an empty
 object, if there are no properties.

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

 This method permits examination of the precise description of all own properties of an
 object. A *property* in JavaScript consists of either a string-valued name or a
 `Symbol` and a property descriptor. Further information about property
 descriptor types and their attributes can be found in
 `Object.defineProperty()`.

A *property descriptor* is a record with some of the following attributes:

`value`

The value associated with the property (data descriptors only).

`writable`

`true` if and only if the value associated with the property may be
 changed (data descriptors only).


`get`

 A function which serves as a getter for the property, or `undefined` if
 there is no getter (accessor descriptors only).


`set`

 A function which serves as a setter for the property, or `undefined` if
 there is no setter (accessor descriptors only).


`configurable`

`true` if and only if the type of this property descriptor may be changed
 and if the property may be deleted from the corresponding object.


`enumerable`

`true` if and only if this property shows up during enumeration of the
 properties on the corresponding object.


Examples
--------

### Creating a shallow copy

 Whereas the `Object.assign()` method will only copy enumerable and own
 properties from a source object to a target object, you are able to use this method and
 `Object.create()` for a shallow copy between two unknown objects:


```js
Object.create(
  Object.getPrototypeOf(obj),
  Object.getOwnPropertyDescriptors(obj),
);
```

### Creating a subclass

 A typical way of creating a subclass is to define the subclass, set its prototype to an
 instance of the superclass, and then define properties on that instance. This can get
 awkward especially for getters and setters. Instead, you can use this code to set the
 prototype:


```js
function superclass() {}
superclass.prototype = {
  // Define the superclass constructor, methods, and properties here
};
function subclass() {}
subclass.prototype = Object.create(superclass.prototype, {
  // Define the subclass constructor, methods, and properties here
});
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-object.getownpropertydescriptors |

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

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

See also
--------

* Polyfill of `Object.getOwnPropertyDescriptors` in `core-js`
* `Object.getOwnPropertyDescriptor()`
* `Object.defineProperty()`
Object.values()
===============

The **`Object.values()`** static method returns an array of a given object's own enumerable string-keyed property values.

Try it
------

Syntax
------


```js
Object.values(obj)
```

### Parameters

`obj`

An object.

### Return value

An array containing the given object's own enumerable string-keyed property values.

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

`Object.values()` returns an array whose elements are values of enumerable string-keyed properties found directly upon `object`. This is the same as iterating with a `for...in` loop, except that a `for...in` loop enumerates properties in the prototype chain as well. The order of the array returned by `Object.values()` is the same as that provided by a `for...in` loop.

If you need the property keys, use `Object.keys()` instead. If you need both the property keys and values, use `Object.entries()` instead.

Examples
--------

### Using Object.values()


```js
const obj = { foo: "bar", baz: 42 };
console.log(Object.values(obj)); // ['bar', 42]

// Array-like object
const arrayLikeObj1 = { 0: "a", 1: "b", 2: "c" };
console.log(Object.values(arrayLikeObj1)); // ['a', 'b', 'c']

// Array-like object with random key ordering
// When using numeric keys, the values are returned in the keys' numerical order
const arrayLikeObj2 = { 100: "a", 2: "b", 7: "c" };
console.log(Object.values(arrayLikeObj2)); // ['b', 'c', 'a']

// getFoo is a non-enumerable property
const myObj = Object.create(
  {},
  {
    getFoo: {
      value() {
        return this.foo;
      },
    },
  },
);
myObj.foo = "bar";
console.log(Object.values(myObj)); // ['bar']
```

### Using Object.values() on primitives

Non-object arguments are coerced to objects. `undefined` and `null` cannot be coerced to objects and throw a `TypeError` upfront. Only strings may have own enumerable properties, while all other primitives return an empty array.


```js
// Strings have indices as enumerable own properties
console.log(Object.values("foo")); // ['f', 'o', 'o']

// Other primitives except undefined and null have no own properties
console.log(Object.values(100)); // []
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-object.values |

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

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

See also
--------

* Polyfill of `Object.values` in `core-js`
* Enumerability and ownership of properties
* `Object.keys()`
* `Object.entries()`
* `Object.prototype.propertyIsEnumerable()`
* `Object.create()`
* `Object.getOwnPropertyNames()`
* `Map.prototype.values()`
Object.is()
===========

The **`Object.is()`** static method determines whether two values are the same value.

Try it
------

Syntax
------


```js
Object.is(value1, value2)
```

### Parameters

`value1`

The first value to compare.

`value2`

The second value to compare.

### Return value

A boolean indicating whether or not the two arguments are the same value.

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

`Object.is()` determines whether two values are the same value. Two values are the same if one of the following holds:

* both `undefined`
* both `null`
* both `true` or both `false`
* both strings of the same length with the same characters in the same order
* both the same object (meaning both values reference the same object in memory)
* both BigInts with the same numeric value
* both symbols that reference the same symbol value
* both numbers and
    + both `+0`
    + both `-0`
    + both `NaN`
    + or both non-zero, not `NaN`, and have the same value

`Object.is()` is not equivalent to the `==` operator. The `==` operator applies various coercions to both sides (if they are not the same type) before testing for equality (resulting in such behavior as `"" == false` being `true`), but `Object.is()` doesn't coerce either value.

`Object.is()` is also *not* equivalent to the `===` operator. The only difference between `Object.is()` and `===` is in their treatment of signed zeros and `NaN` values. The `===` operator (and the `==` operator) treats the number values `-0` and `+0` as equal, but treats `NaN` as not equal to each other.

Examples
--------

### Using Object.is()


```js
// Case 1: Evaluation result is the same as using ===
Object.is(25, 25); // true
Object.is("foo", "foo"); // true
Object.is("foo", "bar"); // false
Object.is(null, null); // true
Object.is(undefined, undefined); // true
Object.is(window, window); // true
Object.is([], []); // false
const foo = { a: 1 };
const bar = { a: 1 };
const sameFoo = foo;
Object.is(foo, foo); // true
Object.is(foo, bar); // false
Object.is(foo, sameFoo); // true

// Case 2: Signed zero
Object.is(0, -0); // false
Object.is(+0, -0); // false
Object.is(-0, -0); // true

// Case 3: NaN
Object.is(NaN, 0 / 0); // true
Object.is(NaN, Number.NaN); // true
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-object.is |

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

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

See also
--------

* Polyfill of `Object.is` in `core-js`
* Equality comparisons and sameness
Object.prototype.toLocaleString()
=================================

The **`toLocaleString()`** method of `Object` instances returns a string representing this object. This method is meant to be overridden by derived objects for locale-specific purposes.

Try it
------

Syntax
------


```js
toLocaleString()
```

### Parameters

None. However, all objects that override this method are expected to accept at most two parameters, corresponding to `locales` and `options`, such as `Date.prototype.toLocaleString`. The parameter positions should not be used for any other purpose.

### Return value

The return value of calling `this.toString()`.

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

All objects that inherit from `Object.prototype` (that is, all except `null`-prototype objects) inherit the `toLocaleString()` method. `Object`'s `toLocaleString` returns the result of calling `this.toString()`.

This function is provided to give objects a generic `toLocaleString` method, even though not all may use it. In the core language, these built-in objects override `toLocaleString` to provide locale-specific formatting:

* `Array`: `Array.prototype.toLocaleString()`
* `Number`: `Number.prototype.toLocaleString()`
* `Date`: `Date.prototype.toLocaleString()`
* `TypedArray`: `TypedArray.prototype.toLocaleString()`
* `BigInt`: `BigInt.prototype.toLocaleString()`
Examples
--------

### Using the base toLocaleString() method

The base `toLocaleString()` method simply calls `toString()`.


```js
const obj = {
  toString() {
    return "My Object";
  },
};
console.log(obj.toLocaleString()); // "My Object"
```

### Array toLocaleString() override

`Array.prototype.toLocaleString()` is used to print array values as a string by invoking each element's `toLocaleString()` method and joining the results with a locale-specific separator. For example:


```js
const testArray = [4, 7, 10];

const euroPrices = testArray.toLocaleString("fr", {
  style: "currency",
  currency: "EUR",
});
// "4,00 €,7,00 €,10,00 €"
```

### Date toLocaleString() override

`Date.prototype.toLocaleString()` is used to print out date displays more suitable for specific locales. For example:


```js
const testDate = new Date();
// "Fri May 29 2020 18:04:24 GMT+0100 (British Summer Time)"

const deDate = testDate.toLocaleString("de");
// "29.5.2020, 18:04:24"

const frDate = testDate.toLocaleString("fr");
// "29/05/2020, 18:04:24"
```

### Number toLocaleString() override

`Number.prototype.toLocaleString()` is used to print out number displays more suitable for specific locales, e.g. with the correct separators. For example:


```js
const testNumber = 2901234564;
// "2901234564"

const deNumber = testNumber.toLocaleString("de");
// "2.901.234.564"

const frNumber = testNumber.toLocaleString("fr");
// "2 901 234 564"
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-object.prototype.tolocalestring |

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

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

See also
--------

* `Object.prototype.toString()`
Object.keys()
=============

The **`Object.keys()`** static method returns an array of a given object's own enumerable string-keyed property names.

Try it
------

Syntax
------


```js
Object.keys(obj)
```

### Parameters

`obj`

An object.

### Return value

An array of strings representing the given object's own enumerable string-keyed property keys.

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

`Object.keys()` returns an array whose elements are strings corresponding to the enumerable string-keyed property names found directly upon `object`. This is the same as iterating with a `for...in` loop, except that a `for...in` loop enumerates properties in the prototype chain as well. The order of the array returned by `Object.keys()` is the same as that provided by a `for...in` loop.

If you need the property values, use `Object.values()` instead. If you need both the property keys and values, use `Object.entries()` instead.

Examples
--------

### Using Object.keys()


```js
// Simple array
const arr = ["a", "b", "c"];
console.log(Object.keys(arr)); // ['0', '1', '2']

// Array-like object
const obj = { 0: "a", 1: "b", 2: "c" };
console.log(Object.keys(obj)); // ['0', '1', '2']

// Array-like object with random key ordering
const anObj = { 100: "a", 2: "b", 7: "c" };
console.log(Object.keys(anObj)); // ['2', '7', '100']

// getFoo is a non-enumerable property
const myObj = Object.create(
  {},
  {
    getFoo: {
      value() {
        return this.foo;
      },
    },
  },
);
myObj.foo = 1;
console.log(Object.keys(myObj)); // ['foo']
```


If you want *all* string-keyed own properties, including non-enumerable ones, see `Object.getOwnPropertyNames()`.

### Using Object.keys() on primitives

Non-object arguments are coerced to objects. `undefined` and `null` cannot be coerced to objects and throw a `TypeError` upfront. Only strings may have own enumerable properties, while all other primitives return an empty array.


```js
// Strings have indices as enumerable own properties
console.log(Object.keys("foo")); // ['0', '1', '2']

// Other primitives except undefined and null have no own properties
console.log(Object.keys(100)); // []
```


**Note:** In ES5, passing a non-object to `Object.keys()` threw a `TypeError`.

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-object.keys |

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

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

See also
--------

* Polyfill of `Object.keys` in `core-js`
* Enumerability and ownership of properties
* `Object.entries()`
* `Object.values()`
* `Object.prototype.propertyIsEnumerable()`
* `Object.create()`
* `Object.getOwnPropertyNames()`
* `Map.prototype.keys()`
Object.isSealed()
=================

 The **`Object.isSealed()`** static method determines if an object is
 sealed.

Try it
------

Syntax
------


```js
Object.isSealed(obj)
```

### Parameters

`obj`

The object which should be checked.

### Return value

A `Boolean` indicating whether or not the given object is sealed.

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

 Returns `true` if the object is sealed, otherwise `false`. An
 object is sealed if it is not extensible and
 if all its properties are non-configurable and therefore not removable (but not
 necessarily non-writable).

Examples
--------

### Using Object.isSealed


```js
// Objects aren't sealed by default.
const empty = {};
Object.isSealed(empty); // false

// If you make an empty object non-extensible,
// it is vacuously sealed.
Object.preventExtensions(empty);
Object.isSealed(empty); // true

// The same is not true of a non-empty object,
// unless its properties are all non-configurable.
const hasProp = { fee: "fie foe fum" };
Object.preventExtensions(hasProp);
Object.isSealed(hasProp); // false

// But make them all non-configurable
// and the object becomes sealed.
Object.defineProperty(hasProp, "fee", {
  configurable: false,
});
Object.isSealed(hasProp); // true

// The easiest way to seal an object, of course,
// is Object.seal.
const sealed = {};
Object.seal(sealed);
Object.isSealed(sealed); // true

// A sealed object is, by definition, non-extensible.
Object.isExtensible(sealed); // false

// A sealed object might be frozen,
// but it doesn't have to be.
Object.isFrozen(sealed); // true
// (all properties also non-writable)

const s2 = Object.seal({ p: 3 });
Object.isFrozen(s2); // false
// ('p' is still writable)

const s3 = Object.seal({
  get p() {
    return 0;
  },
});
Object.isFrozen(s3); // true
// (only configurability matters for accessor properties)
```

### Non-object argument

In ES5, if the argument to this method is not an object (a primitive), then it will cause a `TypeError`. In ES2015, it will return `true` without any errors if a non-object argument is passed, since primitives are, by definition, immutable.


```js
Object.isSealed(1);
// TypeError: 1 is not an object (ES5 code)

Object.isSealed(1);
// true (ES2015 code)
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-object.issealed |

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

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

See also
--------

* `Object.seal()`
* `Object.preventExtensions()`
* `Object.isExtensible()`
* `Object.freeze()`
* `Object.isFrozen()`
Object.getPrototypeOf()
=======================

 The **`Object.getPrototypeOf()`** static method returns the prototype
 (i.e. the value of the internal `[[Prototype]]` property) of the specified
 object.

Try it
------

Syntax
------


```js
Object.getPrototypeOf(obj)
```

### Parameters

`obj`

The object whose prototype is to be returned.

### Return value

The prototype of the given object, which may be `null`.

Examples
--------

### Using getPrototypeOf


```js
const proto = {};
const obj = Object.create(proto);
Object.getPrototypeOf(obj) === proto; // true
```

### Non-object coercion

 In ES5, it will throw a `TypeError` exception if the `obj`
 parameter isn't an object. In ES2015, the parameter will be coerced to an
 `Object`.


```js
Object.getPrototypeOf("foo");
// TypeError: "foo" is not an object (ES5 code)
Object.getPrototypeOf("foo");
// String.prototype (ES2015 code)
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-object.getprototypeof |

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

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

See also
--------

* Polyfill of `Object.getPrototypeOf` in `core-js`
* `Object.prototype.isPrototypeOf()`
* `Object.setPrototypeOf()`
* `Object.prototype.__proto__`
* `Reflect.getPrototypeOf()`
* Object.getPrototypeOf by John Resig (2008)