Design & Download
Your JS Library
in Seconds!!!

Snippet: isPrimitive()

Written by Christopher West (cwest) on November 17, 2015.
Determines if something is a primitive or not. If not a primitive it must be some form of object.
function isPrimitive(arg) {
  var type = typeof arg;
  return arg == undefined || (type != "object" && type != "function");
}

isPrimitive(...) API Documentation

Description

Determines if something is a primitive or not. If not a primitive it must be some form of object.

Parameters

  1. arg {*}:
    The argument which will be determined as being either a primitive (eg. boolean, number, string, etc.) or a non-primitive.

Returns

Returns a boolean. true will be returned if arg is simply a primitive, otherwise false will be returned.