JavaScript/基本数据类型:修订间差异
来自康健生活
无编辑摘要 |
无编辑摘要 |
||
| (未显示同一用户的3个中间版本) | |||
| 第1行: | 第1行: | ||
== 引言 == | == 引言 == | ||
基本数据类型存储的是<code>值</code>,<code>值</code>不可调用。 | 基本数据类型存储的是<code>值</code>,<code>值</code>不可调用。 | ||
{{ | {{Double-columns|<syntaxhighlight lang="javascript"> | ||
undefined.toString();</syntaxhighlight> | undefined.toString();</syntaxhighlight> | ||
|{{Consoleout|<pre>Uncaught TypeError: Cannot read property 'toString' of undefined at <anonymous>:1:11 | |{{Consoleout|<pre>Uncaught TypeError: Cannot read property 'toString' of undefined at <anonymous>:1:11 | ||
</pre>}}}} | </pre>}}}} | ||
== 属性 == | |||
基础数据类型不具备对象属性{{qm|是不是叫对象属性}}。 | |||
{{Double-columns|<syntaxhighlight lang="javascript"> | |||
var foo = 'hello'; | |||
foo = 'world'; | |||
console.log(foo); | |||
foo.bar = 1234; | |||
console.log(foo.bar);</syntaxhighlight>|{{consoleout|<pre> | |||
'world' | |||
undefined</pre>}}}} | |||
== 精度 == | |||
[https://en.wikipedia.org/wiki/IEEE_754 IEEE 754] 规定64位: | |||
* 符号位:1位 | |||
* 指数:11位 | |||
* 有效 精度:53位(显式存储52位) | |||
[[文件:IEEE 754 Double Floating Point Format.svg.png|无|IEEE 754 Double Floating Point Format.svg]] | |||
== 库 == | |||
* bignumber | |||
== 检测 == | |||
<syntaxhighlight lang="javascript"> | |||
String(Number('1152921504735848759'))=='1152921504735848759</syntaxhighlight> | |||
== 强制转换类型 == | == 强制转换类型 == | ||
原始类型被强制转换成 <code>String</code> 类型: | 原始类型被强制转换成 <code>String</code> 类型: | ||
{{ | {{Double-columns|<syntaxhighlight lang="javascript"> | ||
'1'.toString();</syntaxhighlight> | '1'.toString();</syntaxhighlight> | ||
|{{Consoleout|<pre>"1" | |{{Consoleout|<pre>"1" | ||
| 第16行: | 第42行: | ||
原始类型 <code>Number</code> 属于浮点数类型。 | 原始类型 <code>Number</code> 属于浮点数类型。 | ||
{{ | {{Double-columns|<syntaxhighlight lang="javascript"> | ||
0.1 + 0.2 | 0.1 + 0.2 | ||
0.1 + 0.2 !== 0.3</syntaxhighlight> | 0.1 + 0.2 !== 0.3</syntaxhighlight> | ||
| 第22行: | 第48行: | ||
true | true | ||
</pre>}}}} | </pre>}}}} | ||
== 疑点 == | |||
有人传言<code>闭包中的基本数据类型变量不保存在栈内存中,而是保存在堆内存中</code>{{qm}},有待考证。 | |||