JavaScript/typeof:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
无编辑摘要
Kangkk​(留言 | 贡献)
第14行: 第14行:
== 实例 ==
== 实例 ==
{{Leftrightflex|<syntaxhighlight lang="javascript">
{{Leftrightflex|<syntaxhighlight lang="javascript">
typeof Symbol()
typeof function(){}
typeof class C{}
typeof []
typeof {}
typeof true
typeof "str"
typeof 1;
typeof undefined;
typeof undefined;
typeof null;</syntaxhighlight>
typeof null;
|{{Consoleout|<pre>undefined
typeof new String();
object
typeof new Number();
typeof new Array();
typeof new Object();
typeof new Function();
typeof new RegExp();
typeof new Date();
typeof new Error();
typeof 1n;
typeof BigInt("1");</syntaxhighlight>
|{{Consoleout|<pre>"symbol"
"function"
"function"
"object"
"object"
"boolean"
"string"
"number"
"undefined"
"object"
"object"
"object"
"object"
"object"
"function"
"object"
"object"
"object"
"bigint"
"bigint"
</pre>}}
</pre>}}
}}
}}
 
== null ==
类型检测
{{leftrightflex|<syntaxhighlight lang="javascript">!null&&typeof null === "object"</syntaxhighlight>|{{consoleout|<pre>true
</pre>}}}}
== 原理 ==
机器码低三位:
{| class="wikitable"
|-
| 000 || 对象 || 示例
|-
| 010 || 浮点数 || 示例
|-
| 100 || 字符串 || 示例
|-
| 110 || 布尔值 || 示例
|-
| 1 || 整数 || 示例
|}


== undefined 和 null ==
== undefined 和 null ==

2020年6月26日 (五) 06:09的版本

引言

undefined Undefined 类型
boolean Boolean 类型
number Number 类型
string String 类型
object 引用类型或 Null 类型

实例

模板:Leftrightflex

null

类型检测 模板:Leftrightflex

原理

机器码低三位:

000 对象 示例
010 浮点数 示例
100 字符串 示例
110 布尔值 示例
1 整数 示例

undefined 和 null

模板:Leftrightflex