Small JavaScript library that deals with variable types. Abandoned. Add an issue if you want to take over!
JavaScript CSS
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

JSTypes (no longer maintained)

JSTypes is a small JavaScript library that does two things:

  1. Check if variables are of certain types (numbers, strings, undefined)
  2. Reliably create certain values (undefined, NaN, Infinity)

Note that you probably shouldn't use JSTypes unless you need it -- other popular libraries like jQuery and Underscore already have many of these methods. If you aren't using these libraries, then JSTypes might be of help!


var x = 1;
var y = new Number(22);
x instanceof Number;    // false; not what we want!
JSTypes.isNumber(x);    // true
JSTypes.isNumber(y);    // true
var x;
JSTypes.isUndefined(x);    // true
undefined = 10;            // this is terrible code, but it might get written!
JSTypes.isUndefined(x);    // still true
var x = 5;
undefined = 10;
x = undefined;                  // bad: x = 10
x = JSTypes.makeUndefined();    // good: x is now really undefined
JSTypes.isUndefined(x);         // true

I recommend (and do) move this library into your code's namespace if you're writing a library. Just replace all occurrences of JSTypes with your library's namespace.

For licensing info, see LICENSE.txt.


Here's everything in the API.

  • JSTypes.isNumber(toCheck) returns true if something is a number
  • JSTypes.isInteger(toCheck) returns true if something is an integer
  • JSTypes.isString(toCheck) returns true if something is a string
  • JSTypes.isBoolean(toCheck) returns true if something is a boolean
  • JSTypes.isArray(toCheck) returns true if something is an array
  • JSTypes.isDefined(toCheck) returns true if something is defined (will return false for undefined, or null, or NaN)
  • JSTypes.isUndefined(toCheck) returns true if something is undefined
  • JSTypes.isNAN(toCheck) returns true if something is NaN
  • JSTypes.isInfinite(toCheck) returns true of something is positive or negative infinity
  • JSTypes.makeUndefined() always returns undefined, even if it's stupidly redefined
  • JSTypes.makeNaN() always returns NaN, even if it's stupidly redefined
  • JSTypes.makeInfinity() always returns Infinity, even if it's stupidly redefined