Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
In a language with dynamic typing like JavaScript, it's often necessary (and a very good idea) to test the type of variable before performing any operations on it. Although it might not seem like much to test for the type of a variable, it isn't always a freebie, and in practice can simply result in annoyances and bugs because of subtle differences. Base provides a few handy functions to simplify the nuances entailed. Like the other issues we've touched on so far, there are subtleties amongst various browsers involving some of the finer points. The following list summarizes:
isString(/*Any*/ value)
Returns true if value is a String.
isArray(/*Any*/ value)
Returns true if value is an Array.
isFunction(/*Any*/ value)
Returns true if value is a Function.
isObject(/*Any*/ value)
Returns true if value is an Object (including an Array and Function ) or null.
isArrayLike(/*Any*/ value)
Returns true if value is an Array but also allows for more permissive possibilities. For example, the built-in arguments value that can be accessed from within a Function object is especially an oddball in that it does not support built-in methods such as push ; however, it is array-like in that it is a list of values that can be indexed.
isAlien(/*Any*/ value)
Returns true if value is a built-in function or native function such as an ActiveX component but does not respect the normal checks such as the instanceof Function.