Monday, August 12, 2013

Java script: get the type of a variable

To get the type of a variable:

Object.prototype.toString.call( someVar )

Compare the type of a variable:

if( Object.prototype.toString.call( someVar ) === '[object Array]' ) {
    alert( 'Array!' );
}