JavaScript/typeof:修订间差异
来自康健生活
无编辑摘要 |
|||
| 第25行: | 第25行: | ||
== 实例 == | == 实例 == | ||
boolean | boolean | ||
{{ | {{Double-columns|<syntaxhighlight lang="javascript"> | ||
typeof true; | typeof true; | ||
typeof false; | typeof false; | ||
| 第35行: | 第35行: | ||
string | string | ||
{{ | {{Double-columns|<syntaxhighlight lang="javascript"> | ||
typeof "str"; | typeof "str"; | ||
typeof ""; | typeof ""; | ||
| 第44行: | 第44行: | ||
number | number | ||
{{ | {{Double-columns|<syntaxhighlight lang="javascript"> | ||
typeof 1; | typeof 1; | ||
typeof -1; | typeof -1; | ||
| 第57行: | 第57行: | ||
undefined | undefined | ||
{{ | {{Double-columns|<syntaxhighlight lang="javascript"> | ||
typeof undefined; | typeof undefined; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| 第65行: | 第65行: | ||
object | object | ||
{{ | {{Double-columns|<syntaxhighlight lang="javascript"> | ||
typeof []; | typeof []; | ||
typeof {}; | typeof {}; | ||
| 第82行: | 第82行: | ||
}} | }} | ||
{{ | {{Double-columns|<syntaxhighlight lang="javascript"> | ||
typeof function(){}; | typeof function(){}; | ||
typeof class C{}; | typeof class C{}; | ||
| 第93行: | 第93行: | ||
symbol | symbol | ||
{{ | {{Double-columns|<syntaxhighlight lang="javascript"> | ||
typeof Symbol(); | typeof Symbol(); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| 第99行: | 第99行: | ||
}} | }} | ||
{{ | {{Double-columns|<syntaxhighlight lang="javascript"> | ||
typeof 1n; | typeof 1n; | ||
typeof BigInt("1"); | typeof BigInt("1"); | ||
| 第108行: | 第108行: | ||
== null == | == null == | ||
类型检测 | 类型检测 | ||
{{ | {{Double-columns|<syntaxhighlight lang="javascript">!null&&typeof null === "object"</syntaxhighlight>|{{consoleout|<pre>true | ||
</pre>}}}} | </pre>}}}} | ||
== 原理 == | == 原理 == | ||
| 第130行: | 第130行: | ||
== undefined 和 null == | == undefined 和 null == | ||
{{ | {{Double-columns|<syntaxhighlight lang="javascript"> | ||
undefined == null; | undefined == null; | ||
undefined === null; | undefined === null; | ||
| 第141行: | 第141行: | ||
}} | }} | ||
== es6 == | == es6 == | ||
{{ | {{Double-columns|<syntaxhighlight lang="javascript"> | ||
typeof new Set(); | typeof new Set(); | ||
typeof new Map(); | typeof new Map(); | ||