Function isPrimitiveType

  • Identifies whether the provided value is a JavaScript primitive which is when is it not an object and has no methods or properties. There are 6 primitive data types:

    • string
    • number
    • bigint
    • boolean
    • undefined
    • symbol

    Most of the time, a primitive value is represented directly at the lowest level of the language implementation.

    All primitives are immutable; that is, they cannot be altered. It is important not to confuse a primitive itself with a variable assigned a primitive value. The variable may be reassigned to a new value, but the existing value can not be changed in the ways that objects, arrays, and functions can be altered. The language does not offer utilities to mutate primitive values.

    Parameters

    • theType: string

      The type as a string value to be checked whther it's a primitive type, this should be the value returned from typeof value.

    Returns boolean

    Since

    0.9.6

    Example

    isPrimitiveType(null);                   // false
    isPrimitiveType(undefined); // false
    isPrimitiveType("null"); // false
    isPrimitiveType("undefined"); // false
    isPrimitiveType("1"); // false
    isPrimitiveType("aa"); // false
    isPrimitiveType(1); // false
    isPrimitiveType(Number(2)); // false
    isPrimitiveType(""); // false
    isPrimitiveType(String("")); // false
    isPrimitiveType(true); // false
    isPrimitiveType(false); // false
    isPrimitiveType("true"); // false
    isPrimitiveType("false"); // false
    isPrimitiveType(BigInt(42)); // false
    isPrimitiveType(Symbol.for("Hello")); // false

    isPrimitiveType("string"); // true
    isPrimitiveType("number"); // true
    isPrimitiveType("boolean"); // true
    isPrimitiveType("undefined"); // true
    isPrimitiveType("symbol"); // true
    isPrimitiveType("bigint"); // true