Number is primitive

JavaScript, Type · Oct 22, 2020

Checks if the passed value is primitive or not.

  • Create an object from val and compare it with val to determine if the passed value is primitive (i.e. not equal to the created object).
const isPrimitive = val => Object(val) !== val;
isPrimitive(null); // true
isPrimitive(undefined); // true
isPrimitive(50); // true
isPrimitive('Hello!'); // true
isPrimitive(false); // true
isPrimitive(Symbol()); // true
isPrimitive([]); // false
isPrimitive({}); // false

More like this

  • Value is object

    Checks if the passed value is an object or not.

    JavaScript, Type · Jan 7, 2021

  • Value is string

    Checks if the given argument is a string. Only works for string primitives.

    JavaScript, Type · Oct 20, 2020

  • Value is number

    Checks if the given argument is a number.

    JavaScript, Type · Sep 15, 2020