1. 程式人生 > >js中typeof的使用

js中typeof的使用

js

typeof(number,string,undefined,boolean,object)

會出現以上5種情況中的一種

console.log(typeof(‘123‘));//string
console.log(typeof(123));.//number
console.log(typeof(10.1));//number
console.log(typeof(NaN));//number
console.log(typeof(undefined));//undefined
console.log(typeof(true));//boolean
console.log(typeof([1,2,3]));//object
console.log(typeof({
  ‘username‘:‘user1‘,
  ‘say‘:function(){alert(‘hello‘)}
}));//object
console.log(typeof(document));//object
console.log(typeof(new
Object()));//object
console.log(typeof(null));//object



本文出自 “Rcid” 博客,請務必保留此出處http://13419255.blog.51cto.com/13409255/1975773

js中typeof的使用