Files
30-seconds-of-code/snippets/is.md
2018-01-17 21:23:46 +02:00

443 B

is

Checks if the provided value is of the specified type.

Use the instanceof operator to check if the provided value is of the specified type.

const is = (type, val) => val instanceof type;
is(Array,[1]); // true
is(ArrayBuffer, new ArrayBuffer()); // true
is(Map, new Map()); // true
is(RegExp, /./g); // true
is(Set, new Set()); // true
is(WeakMap, new WeakMap()); // true
is(WeakSet, new WeakSet()); // true