Type of value

JavaScript, Type · Oct 19, 2020

Returns the native type of a value.

const getType = v =>
  (v === undefined ? 'undefined' : v === null ? 'null' : v.constructor.name);
getType(new Set([1, 2, 3])); // 'Set'

More like this

  • Value is boolean

    JavaScript, Type

    Checks if the given argument is a native boolean element.

  • Collection is empty

    JavaScript, Type

    Checks if the a value is an empty object/collection, has no enumerable properties or is any type that is not considered a collection.

  • Value is promise-like

    JavaScript, Type

    Checks if an object looks like a Promise.