Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/454.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用typeof检查基本类型javascript_Javascript_Typeof - Fatal编程技术网

使用typeof检查基本类型javascript

使用typeof检查基本类型javascript,javascript,typeof,Javascript,Typeof,嗨,我想使用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来检查这一点,因为我刚刚开始学习java

嗨,我想使用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。谢谢大家!

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

这里有一些

如果您不知道操作员是如何工作的,请阅读。如果您不理解所有内容,请进行澄清。鉴于您在伪代码中明确使用了字符串
typeof
of,您在哪里被卡住了?提示:
typeof
对于第一部分很有用。顺便说一句:用户通过
prompt()
获取的任何输入都将是一个字符串。可能是FWIW的重复,数组在JS中不是数据类型(这篇文章让它看起来像是)。@FelixKling很抱歉,我不知道FWIW是什么意思,但无论如何,谢谢你。虽然它似乎返回对象,不是吗?FWIW的意思是“为了它的价值”。是的,它返回的“object”是正确的,但是本文的标题是“数据类型”,并列出了数组,即使它不是数据类型。“我只是想指出这个小小的差异。”费利克斯克林说,“呵呵