Skip to content

Instantly share code, notes, and snippets.

@zhanhongtao
Last active December 22, 2015 08:49
Show Gist options
  • Save zhanhongtao/6447735 to your computer and use it in GitHub Desktop.
Save zhanhongtao/6447735 to your computer and use it in GitHub Desktop.
type
function type(s) {
return Object.prototype.toString.call(s).slice(8,-1).toLowerCase();
}
console.assert( type( null ) == 'null', 'null' );
console.assert( type( undefined ) == 'undefined', 'undefined' );
console.assert( type( [] ) == 'array', '[]' );
console.assert( type( {} ) == 'object', 'object' );
console.assert( type( false ) == 'boolean', 'false' );
console.assert( type( 1.2 ) == 'number', '1.2' );
console.assert( type( 'sogou' ) == 'string', 'sogou' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment