JavaScript/typeof:修订间差异
来自康健生活
| 第24行: | 第24行: | ||
== 实例 == | == 实例 == | ||
boolean | |||
{{Leftrightflex|<syntaxhighlight lang="javascript"> | |||
typeof true; | |||
typeof false; | |||
typeof (2 > 1); | |||
</syntaxhighlight> | |||
|{{Consoleout|<pre>'boolean' | |||
</pre>}} | |||
}} | |||
string | |||
{{Leftrightflex|<syntaxhighlight lang="javascript"> | |||
typeof "str"; | |||
typeof ""; | |||
</syntaxhighlight> | |||
|{{Consoleout|<pre>'string' | |||
</pre>}} | |||
}} | |||
number | |||
{{Leftrightflex|<syntaxhighlight lang="javascript"> | {{Leftrightflex|<syntaxhighlight lang="javascript"> | ||
typeof 1; | typeof 1; | ||
typeof -1; | |||
typeof 0; | |||
typeof Math.PI; | |||
typeof Infinity; | |||
typeof NaN; | |||
</syntaxhighlight> | |||
|{{Consoleout|<pre>'number' | |||
</pre>}} | |||
}} | |||
undefined | |||
{{Leftrightflex|<syntaxhighlight lang="javascript"> | |||
typeof undefined; | typeof undefined; | ||
typeof | </syntaxhighlight> | ||
|{{Consoleout|<pre>'undefined' | |||
</pre>}} | |||
}} | |||
object | |||
{{Leftrightflex|<syntaxhighlight lang="javascript"> | |||
typeof []; | |||
typeof {}; | |||
typeof new RegExp(); | |||
typeof new Date(); | |||
typeof new Error(); | |||
typeof new String(); | typeof new String(); | ||
typeof new Number(); | typeof new Number(); | ||
typeof new Array(); | typeof new Array(); | ||
typeof new Object(); | typeof new Object(); | ||
typeof new Boolean(); | |||
typeof null; | |||
</syntaxhighlight> | |||
|{{Consoleout|<pre>'object' | |||
</pre>}} | |||
}} | |||
{{Leftrightflex|<syntaxhighlight lang="javascript"> | |||
typeof function(){}; | |||
typeof class C{}; | |||
typeof new Function(); | typeof new Function(); | ||
typeof | typeof Number; | ||
typeof | typeof Array; | ||
typeof | </syntaxhighlight> | ||
|{{Consoleout|<pre>'function'</pre>}} | |||
}} | |||
symbol | |||
{{Leftrightflex|<syntaxhighlight lang="javascript"> | |||
typeof Symbol(); | |||
</syntaxhighlight> | |||
|{{Consoleout|<pre>'symbol'</pre>}} | |||
}} | |||
{{Leftrightflex|<syntaxhighlight lang="javascript"> | |||
typeof 1n; | typeof 1n; | ||
typeof BigInt("1");</syntaxhighlight> | typeof BigInt("1"); | ||
|{{Consoleout|<pre> | </syntaxhighlight> | ||
|{{Consoleout|<pre>'bigint'</pre>}} | |||
</pre>}} | |||
}} | }} | ||
== null == | == null == | ||
类型检测 | 类型检测 | ||