JavaScriptプログラムに関する各種メモ書き

JavaScriptで Date型 の判別

console.log( Object.prototype.toString.call(undefined) );				// object undefined
console.log( Object.prototype.toString.call(null) );					// object Null
console.log( Object.prototype.toString.call(123456) );					// object Number
console.log( Object.prototype.toString.call(Infinity) );				// object Number
console.log( Object.prototype.toString.call(NaN) );						// object Number
console.log( Object.prototype.toString.call('hoge') );					// object String
console.log( Object.prototype.toString.call(true) );					// object Boolean
console.log( Object.prototype.toString.call([]) );						// object Array
console.log( Object.prototype.toString.call({aaa:'bbb'}) );				// object Objec
console.log( Object.prototype.toString.call(new Date()) );				// object Date
console.log( Object.prototype.toString.call(new Map()) );				// object Map
console.log( Object.prototype.toString.call(new Set()) );				// object Set
console.log( Object.prototype.toString.call(function() {}) );			// object Function
console.log( Object.prototype.toString.call(new String('hogehoge')) );	// object String
console.log( Object.prototype.toString.call(new Number(123456)) );		// object Number
console.log( Object.prototype.toString.call(new Boolean(true)) );		// object Boolean
console.log( Object.prototype.toString.call(Math) );					// object Math
console.log( Object.prototype.toString.call(JSON) );					// object JSON

引用 : shorturl.at/uT013

No.2148
01/29 23:30

edit