recursal/MDN huggingface dataset:
Date.prototype.setDate()
========================

The **`setDate()`** method of `Date` instances changes the day of the month for this date according to local time.

Try it
------

Syntax
------


```js
setDate(dateValue)
```

### Parameters

`dateValue`

An integer representing the day of the month.

### Return value

Changes the `Date` object in place, and returns its new timestamp. If `dateValue` is `NaN` (or other values that get coerced to `NaN`, such as `undefined`), the date is set to Invalid Date and `NaN` is returned.

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

If you specify a number outside the expected range, the date information in the `Date` object is updated accordingly. For example, if the `Date` object holds June 1st, a `dateValue` of 40 changes the date to July 10th, while a `dateValue` of 0 changes the date to the last day of the previous month, May 31st.

Examples
--------

### Using setDate()


```js
const theBigDay = new Date(1962, 6, 7, 12); // noon of 1962-07-07 (7th of July 1962, month is 0-indexed)
const theBigDay2 = new Date(theBigDay).setDate(24); // 1962-07-24 (24th of July 1962)
const theBigDay3 = new Date(theBigDay).setDate(32); // 1962-08-01 (1st of August 1962)
const theBigDay4 = new Date(theBigDay).setDate(22); // 1962-07-22 (22nd of July 1962)
const theBigDay5 = new Date(theBigDay).setDate(0); // 1962-06-30 (30th of June 1962)
const theBigDay6 = new Date(theBigDay).setDate(98); // 1962-10-06 (6th of October 1962)
const theBigDay7 = new Date(theBigDay).setDate(-50); // 1962-05-11 (11th of May 1962)
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-date.prototype.setdate |

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

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

See also
--------

* `Date()`
* `Date.prototype.getDate()`
* `Date.prototype.setUTCDate()`
Date.prototype.getUTCDay()
==========================

The **`getUTCDay()`** method of `Date` instances returns the day of the week for this date according to universal time, where 0 represents Sunday.

Try it
------

Syntax
------


```js
getUTCDay()
```

### Parameters

None.

### Return value

An integer corresponding to the day of the week for the given date according to universal time: 0 for Sunday, 1 for Monday, 2 for Tuesday, and so on. Returns `NaN` if the date is invalid.

Examples
--------

### Using getUTCDay()

The following example assigns the weekday portion of the current date to the variable `weekday`.


```js
const today = new Date();
const weekday = today.getUTCDay();
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-date.prototype.getutcday |

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

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

See also
--------

* `Date.prototype.getUTCDate()`
* `Date.prototype.getDay()`
* `Date.prototype.setUTCDate()`
Date.prototype.setSeconds()
===========================

The **`setSeconds()`** method of `Date` instances changes the seconds and/or milliseconds for this date according to local time.

Try it
------

Syntax
------


```js
setSeconds(secondsValue)
setSeconds(secondsValue, msValue)
```

### Parameters

`secondsValue`

An integer between 0 and 59 representing the seconds.

`msValue` Optional

An integer between 0 and 999 representing the milliseconds.

### Return value

Changes the `Date` object in place, and returns its new timestamp. If a parameter is `NaN` (or other values that get coerced to `NaN`, such as `undefined`), the date is set to Invalid Date and `NaN` is returned.

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

 If you do not specify the `msValue` parameter, the value returned
 from the `getMilliseconds()` method is
 used.

 If a parameter you specify is outside of the expected range, `setSeconds()`
 attempts to update the date information in the `Date` object accordingly.
 For example, if you use 100 for `secondsValue`, the minutes stored
 in the `Date` object will be incremented by 1, and 40 will be used for
 seconds.

Examples
--------

### Using setSeconds()


```js
const theBigDay = new Date();
theBigDay.setSeconds(30);
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-date.prototype.setseconds |

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

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

See also
--------

* `Date.prototype.getSeconds()`
* `Date.prototype.setUTCSeconds()`
Date.prototype.getHours()
=========================

The **`getHours()`** method of `Date` instances returns the hours for this date according to local time.

Try it
------

Syntax
------


```js
getHours()
```

### Parameters

None.

### Return value

An integer, between 0 and 23, representing the hours for the given date according to local time. Returns `NaN` if the date is invalid.

Examples
--------

### Using getHours()

The `hours` variable has value `23`, based on the value of the `Date` object `xmas95`.


```js
const xmas95 = new Date("1995-12-25T23:15:30");
const hours = xmas95.getHours();

console.log(hours); // 23
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-date.prototype.gethours |

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

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

See also
--------

* `Date.prototype.getUTCHours()`
* `Date.prototype.setHours()`
Date.prototype.getUTCMilliseconds()
===================================

The **`getUTCMilliseconds()`** method of `Date` instances returns the milliseconds for this date according to universal time.

Try it
------

Syntax
------


```js
getUTCMilliseconds()
```

### Parameters

None.

### Return value

An integer, between 0 and 999, representing the milliseconds for the given date according to universal time. Returns `NaN` if the date is invalid.

Not to be confused with the timestamp. To get the total milliseconds since the epoch, use the `getTime()` method.

Examples
--------

### Using getUTCMilliseconds()

The following example assigns the milliseconds portion of the current time to the variable `milliseconds`.


```js
const today = new Date();
const milliseconds = today.getUTCMilliseconds();
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-date.prototype.getutcmilliseconds |

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

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

See also
--------

* `Date.prototype.getMilliseconds()`
* `Date.prototype.setUTCMilliseconds()`
Int32Array() constructor
========================

The **`Int32Array()`** constructor creates `Int32Array` objects. The contents are initialized to `0`.

Syntax
------


```js
new Int32Array()
new Int32Array(length)
new Int32Array(typedArray)
new Int32Array(object)

new Int32Array(buffer)
new Int32Array(buffer, byteOffset)
new Int32Array(buffer, byteOffset, length)
```


**Note:** `Int32Array()` can only be constructed with `new`. Attempting to call it without `new` throws a `TypeError`.

### Parameters

See `TypedArray`.

### Exceptions

See `TypedArray`.

Examples
--------

### Different ways to create an Int32Array


```js
// From a length
const int32 = new Int32Array(2);
int32[0] = 42;
console.log(int32[0]); // 42
console.log(int32.length); // 2
console.log(int32.BYTES\_PER\_ELEMENT); // 4

// From an array
const x = new Int32Array([21, 31]);
console.log(x[1]); // 31

// From another TypedArray
const y = new Int32Array(x);
console.log(y[0]); // 21

// From an ArrayBuffer
const buffer = new ArrayBuffer(32);
const z = new Int32Array(buffer, 4, 4);
console.log(z.byteOffset); // 4

// From an iterable
const iterable = (function\* () {
  yield\* [1, 2, 3];
})();
const int32FromIterable = new Int32Array(iterable);
console.log(int32FromIterable);
// Int32Array [1, 2, 3]
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-typedarray-constructors |

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

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

See also
--------

* Polyfill of `Int32Array` in `core-js`
* JavaScript typed arrays guide
* `TypedArray`
* `ArrayBuffer`
* `DataView`
GeneratorFunction() constructor
===============================

The **`GeneratorFunction()`** constructor creates `GeneratorFunction` objects.

Note that `GeneratorFunction` is *not* a global object. It can be obtained with the following code:


```js
const GeneratorFunction = function\* () {}.constructor;
```


The `GeneratorFunction()` constructor is not intended to be used directly, and all caveats mentioned in the `Function()` description apply to `GeneratorFunction()`.

Syntax
------


```js
new GeneratorFunction(functionBody)
new GeneratorFunction(arg1, functionBody)
new GeneratorFunction(arg1, arg2, functionBody)
new GeneratorFunction(arg1, arg2, /\* …, \*/ argN, functionBody)

GeneratorFunction(functionBody)
GeneratorFunction(arg1, functionBody)
GeneratorFunction(arg1, arg2, functionBody)
GeneratorFunction(arg1, arg2, /\* …, \*/ argN, functionBody)
```


**Note:** `GeneratorFunction()` can be called with or without `new`. Both create a new `GeneratorFunction` instance.

### Parameters

See `Function()`.

Examples
--------

### Creating and using a GeneratorFunction() constructor


```js
const GeneratorFunction = function\* () {}.constructor;
const g = new GeneratorFunction("a", "yield a \* 2");
const iterator = g(10);
console.log(iterator.next().value); // 20
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-generatorfunction-constructor |

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

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

See also
--------

* `function*`
* `function*` expression
* `Function()` constructor
* Iterators and generators guide
* Functions
Proxy() constructor
===================

The **`Proxy()`** constructor creates `Proxy` objects.

Syntax
------


```js
new Proxy(target, handler)
```


**Note:** `Proxy()` can only be constructed with `new`. Attempting to call it without `new` throws a `TypeError`.

### Parameters

`target`

 A target object to wrap with `Proxy`. It can be any sort of object,
 including a native array, a function, or even another proxy.


`handler`

 An object whose properties are functions that define the behavior of the proxy when
 an operation is performed on it.


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

 Use the `Proxy()` constructor to create a new `Proxy` object.
 This constructor takes two mandatory arguments:

* `target` is the object for which you want to create the proxy
* `handler` is the object that defines the custom behavior of the proxy.

 An empty handler will create a proxy that behaves, in almost all respects, exactly like
 the target. By defining any of a set group of functions on the `handler`
 object, you can customize specific aspects of the proxy's behavior. For example, by
 defining `get()` you can provide a customized version of the target's
 property accessor.

### Handler functions

 This section lists all the handler functions you can define. Handler functions are
 sometimes called *traps*, because they trap calls to the underlying target
 object.

`handler.apply()`

A trap for a function call.

`handler.construct()`

A trap for the `new` operator.

`handler.defineProperty()`

A trap for `Object.defineProperty`.

`handler.deleteProperty()`

A trap for the `delete` operator.

`handler.get()`

A trap for getting property values.

`handler.getOwnPropertyDescriptor()`

A trap for `Object.getOwnPropertyDescriptor`.

`handler.getPrototypeOf()`

A trap for `Object.getPrototypeOf`.

`handler.has()`

A trap for the `in` operator.

`handler.isExtensible()`

A trap for `Object.isExtensible`.

`handler.ownKeys()`

 A trap for `Object.getOwnPropertyNames` and
 `Object.getOwnPropertySymbols`.


`handler.preventExtensions()`

A trap for `Object.preventExtensions`.

`handler.set()`

A trap for setting property values.

`handler.setPrototypeOf()`

A trap for `Object.setPrototypeOf`.

Examples
--------

### Selectively proxy property accessors

 In this example the target has two properties, `notProxied` and
 `proxied`. We define a handler that returns a different value for
 `proxied`, and lets any other accesses through to the target.


```js
const target = {
  notProxied: "original value",
  proxied: "original value",
};

const handler = {
  get(target, prop, receiver) {
    if (prop === "proxied") {
      return "replaced value";
    }
    return Reflect.get(...arguments);
  },
};

const proxy = new Proxy(target, handler);

console.log(proxy.notProxied); // "original value"
console.log(proxy.proxied); // "replaced value"
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-proxy-constructor |

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

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

See also
--------

* Meta programming guide
* `Reflect`
handler.getPrototypeOf()
========================

The **`handler.getPrototypeOf()`** method is a trap for the `[[GetPrototypeOf]]` object internal method, which is used by operations such as `Object.getPrototypeOf()`.

Try it
------

Syntax
------


```js
new Proxy(obj, {
  getPrototypeOf(target) {
    // …
  }
});
```

### Parameters

 The following parameter is passed to the `getPrototypeOf()` method.
 `this` is bound to the handler.

`target`

The target object.

### Return value

The `getPrototypeOf()` method must return an object or `null`.

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

### Interceptions

This trap can intercept these operations:

* `Object.getPrototypeOf()`
* `Reflect.getPrototypeOf()`
* `__proto__`
* `Object.prototype.isPrototypeOf()`
* `instanceof`

Or any other operation that invokes the `[[GetPrototypeOf]]` internal method.

### Invariants

If the following invariants are violated, the trap throws a `TypeError` when invoked.

* `getPrototypeOf()` method must return an object or `null`.
* If `target` is not extensible,
 `Object.getPrototypeOf(proxy)` method must return the same
 value as `Object.getPrototypeOf(target)`.
Examples
--------

### Basic usage


```js
const obj = {};
const proto = {};
const handler = {
  getPrototypeOf(target) {
    console.log(target === obj); // true
    console.log(this === handler); // true
    return proto;
  },
};

const p = new Proxy(obj, handler);
console.log(Object.getPrototypeOf(p) === proto); // true
```

### Five ways to trigger the getPrototypeOf trap


```js
const obj = {};
const p = new Proxy(obj, {
  getPrototypeOf(target) {
    return Array.prototype;
  },
});
console.log(
  Object.getPrototypeOf(p) === Array.prototype, // true
  Reflect.getPrototypeOf(p) === Array.prototype, // true
  p.__proto__ === Array.prototype, // true
  Array.prototype.isPrototypeOf(p), // true
  p instanceof Array, // true
);
```

### Two kinds of exceptions


```js
const obj = {};
const p = new Proxy(obj, {
  getPrototypeOf(target) {
    return "foo";
  },
});
Object.getPrototypeOf(p); // TypeError: "foo" is not an object or null

const obj2 = Object.preventExtensions({});
const p2 = new Proxy(obj2, {
  getPrototypeOf(target) {
    return {};
  },
});
Object.getPrototypeOf(p2); // TypeError: expected same prototype value
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-proxy-object-internal-methods-and-internal-slots-getprototypeof |

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

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

See also
--------

* `Proxy`
* `Proxy()` constructor
* `Object.getPrototypeOf()`
* `Reflect.getPrototypeOf()`
handler.deleteProperty()
========================

The **`handler.deleteProperty()`** method is a trap for the `[[Delete]]` object internal method, which is used by operations such as the `delete` operator.

Try it
------

Syntax
------


```js
new Proxy(target, {
  deleteProperty(target, property) {
  }
});
```

### Parameters

 The following parameters are passed to the `deleteProperty()` method.
 `this` is bound to the handler.

`target`

The target object.

`property`

The name or `Symbol` of the property to delete.

### Return value

 The `deleteProperty()` method must return a boolean value indicating
 whether or not the property has been successfully deleted.

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

### Interceptions

This trap can intercept these operations:

* The `delete` operator: `delete proxy[foo]` and
 `delete proxy.foo`
* `Reflect.deleteProperty()`

Or any other operation that invokes the `[[Delete]]` internal method.

### Invariants

If the following invariants are violated, the trap throws a `TypeError` when invoked.

* A property cannot be deleted, if it exists as a non-configurable own property of the
 target object.
Examples
--------

### Trapping the delete operator

The following code traps the `delete` operator.


```js
const p = new Proxy(
  {},
  {
    deleteProperty(target, prop) {
      if (!(prop in target)) {
        console.log(`property not found: ${prop}`);
        return false;
      }
      delete target[prop];
      console.log(`property removed: ${prop}`);
      return true;
    },
  },
);

p.a = 10;
console.log("a" in p); // true

const result1 = delete p.a; // "property removed: a"
console.log(result1); // true
console.log("a" in p); // false

const result2 = delete p.a; // "property not found: a"
console.log(result2); // false
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-proxy-object-internal-methods-and-internal-slots-delete-p |

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

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

See also
--------

* `Proxy`
* `Proxy()` constructor
* `delete`
* `Reflect.deleteProperty()`
handler.getOwnPropertyDescriptor()
==================================

The **`handler.getOwnPropertyDescriptor()`** method is a trap for the `[[GetOwnProperty]]` object internal method, which is used by operations such as `Object.getOwnPropertyDescriptor()`.

Try it
------

Syntax
------


```js
new Proxy(target, {
  getOwnPropertyDescriptor(target, prop) {
  }
});
```

### Parameters

The following parameters are passed to the `getOwnPropertyDescriptor()` method. `this` is bound to the handler.

`target`

The target object.

`prop`

The name of the property whose description should be retrieved.

### Return value

The `getOwnPropertyDescriptor()` method must return an object or `undefined`.

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

### Interceptions

This trap can intercept these operations:

* `Object.getOwnPropertyDescriptor()`
* `Reflect.getOwnPropertyDescriptor()`

Or any other operation that invokes the `[[GetOwnProperty]]` internal method.

### Invariants

If the following invariants are violated, the trap throws a `TypeError` when invoked.

* `getOwnPropertyDescriptor()` must return an object or `undefined`.
* A property cannot be reported as non-existent, if it exists as a non-configurable own property of the target object.
* A property cannot be reported as non-existent, if it exists as an own property of the target object and the target object is not extensible.
* A property cannot be reported as existent, if it does not exists as an own property of the target object and the target object is not extensible.
* A property cannot be reported as non-configurable, if it does not exists as an own property of the target object or if it exists as a configurable own property of the target object.
* The result of `Object.getOwnPropertyDescriptor(target)` can be applied to the target object using `Object.defineProperty()` and will not throw an exception.
Examples
--------

### Trapping of getOwnPropertyDescriptor

The following code traps `Object.getOwnPropertyDescriptor()`.


```js
const p = new Proxy(
  { a: 20 },
  {
    getOwnPropertyDescriptor(target, prop) {
      console.log(`called: ${prop}`);
      return { configurable: true, enumerable: true, value: 10 };
    },
  },
);

console.log(Object.getOwnPropertyDescriptor(p, "a").value);
// "called: a"
// 10
```


The following code violates an invariant.


```js
const obj = { a: 10 };
Object.preventExtensions(obj);
const p = new Proxy(obj, {
  getOwnPropertyDescriptor(target, prop) {
    return undefined;
  },
});

Object.getOwnPropertyDescriptor(p, "a"); // TypeError is thrown
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-proxy-object-internal-methods-and-internal-slots-getownproperty-p |

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

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

See also
--------

* `Proxy`
* `Proxy()` constructor
* `Object.getOwnPropertyDescriptor()`
* `Reflect.getOwnPropertyDescriptor()`
handler.set()
=============

The **`handler.set()`** method is a trap for the `[[Set]]` object internal method, which is used by operations such as using property accessors to set a property's value.

Try it
------

Syntax
------


```js
new Proxy(target, {
  set(target, property, value, receiver) {
  }
});
```

### Parameters

 The following parameters are passed to the `set()` method. `this`
 is bound to the handler.

`target`

The target object.

`property`

The name or `Symbol` of the property to set.

`value`

The new value of the property to set.

`receiver`

 The object to which the assignment was originally directed. This is usually the
 proxy itself. But a `set()` handler can also be called indirectly, via
 the prototype chain or various other ways.


 For example, suppose a script does
 `obj.name = "jen"`, and `obj` is not a
 proxy, and has no own property `.name`, but it has a proxy on its
 prototype chain. That proxy's `set()` handler will be called, and
 `obj` will be passed as the receiver.


### Return value

The `set()` method should return a boolean value.

* Return `true` to indicate that assignment succeeded.
* If the `set()` method returns `false`, and the assignment
 happened in strict-mode code, a `TypeError` will be thrown.
Description
-----------

### Interceptions

This trap can intercept these operations:

* Property assignment: `proxy[foo] = bar` and `proxy.foo = bar`
* `Reflect.set()`

Or any other operation that invokes the `[[Set]]` internal method.

### Invariants

If the following invariants are violated, the trap throws a `TypeError` when invoked.

* Cannot change the value of a property to be different from the value of the
 corresponding target object property if the corresponding target object property is a
 non-writable, non-configurable data property.
* Cannot set the value of a property if the corresponding target object property is a
 non-configurable accessor property that has `undefined` as its
 `[[Set]]` attribute.
* In strict mode, a `false` return value from the `set()`
 handler will throw a `TypeError` exception.
Examples
--------

### Trap setting of a property value

The following code traps setting a property value.


```js
const p = new Proxy(
  {},
  {
    set(target, prop, value, receiver) {
      target[prop] = value;
      console.log(`property set: ${prop} = ${value}`);
      return true;
    },
  },
);

console.log("a" in p); // false

p.a = 10; // "property set: a = 10"
console.log("a" in p); // true
console.log(p.a); // 10
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-proxy-object-internal-methods-and-internal-slots-set-p-v-receiver |

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

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

See also
--------

* `Proxy`
* `Proxy()` constructor
* `Reflect.set()`