您好我想使用javascripfor示例检查基本类型
var x //some kind of input is needed like prompt?
if x is a string then alert typeof x is a string
else if x is a boolean alert typeof x is a boolean
else
return alert x is a number
我不知道如何使用typeof来检查这个因为我刚开始学习javascript。谢谢!
答案 0 :(得分:0)
typeof "John" // Returns string
typeof 3.14 // Returns number
typeof false // Returns boolean
typeof [1,2,3,4] // Returns object
typeof {name:'John', age:34} // Returns object
这里有一些documentation