Design & Download
Your JS Library
in Seconds!!!

Snippet: Type Checking Shortcuts

Written by Christopher West (cwest) on October 29, 2015.
Creates type-checking shortcut functions: isArguments(), isArray(), isBoolean(), isDate(), isFunction(), isNull(), isNumber(), isObject(), isRegExp(), isString(), and isUndefined().
'Arguments Array Boolean Date Function null Number Object RegExp String undefined'.replace(/(\w)(\w+)/g, function(typeName, letter1, otherLetters) {
  YourJS['is' + letter1.toUpperCase() + otherLetters] = function(o) {
    return typeOf(o, typeName);
  };
});

isArguments(obj) API Documentation

Description

Determines if something is an Arguments object defined after calling a function.

Parameters

  1. obj {*}:
    The value to be checked.

Returns

Returns true if obj is an Arguments object, otherwise false is returned.

isArray(obj) API Documentation

Description

Determines if something is an Array object.

Parameters

  1. obj {*}:
    The value to be checked.

Returns

Returns true if obj is an Array object, otherwise false is returned.

isBoolean(obj) API Documentation

Description

Determines if something is Boolean.

Parameters

  1. obj {*}:
    The value to be checked.

Returns

Returns true if obj is Boolean, otherwise false is returned.

isDate(obj) API Documentation

Description

Determines if something is a Date object.

Parameters

  1. obj {*}:
    The value to be checked.

Returns

Returns true if obj is a Date object, otherwise false is returned.

isFunction(obj) API Documentation

Description

Determines if something is a Function.

Parameters

  1. obj {*}:
    The value to be checked.

Returns

Returns true if obj is a Function, otherwise false is returned.

isNull(obj) API Documentation

Description

Determines if something is null.

Parameters

  1. obj {*}:
    The value to be checked.

Returns

Returns true if obj is null, otherwise false is returned.

isNumber(obj) API Documentation

Description

Determines if something is a Number.

Parameters

  1. obj {*}:
    The value to be checked.

Returns

Returns true if obj is a Number, otherwise false is returned.

isObject(obj) API Documentation

Description

Determines if something is an Object.

Parameters

  1. obj {*}:
    The value to be checked.

Returns

Returns true if obj is an Object, otherwise false is returned.

isRegExp(obj) API Documentation

Description

Determines if something is a RegExp object.

Parameters

  1. obj {*}:
    The value to be checked.

Returns

Returns true if obj is a RegExp object, otherwise false is returned.

isString(obj) API Documentation

Description

Determines if something is a String.

Parameters

  1. obj {*}:
    The value to be checked.

Returns

Returns true if obj is a String, otherwise false is returned.

isUndefined(obj) API Documentation

Description

Determines if something is undefined.

Parameters

  1. obj {*}:
    The value to be checked.

Returns

Returns true if obj is undefined, otherwise false is returned.