JavaScript/基本数据类型:修订间差异
来自康健生活
无编辑摘要 |
|||
| 第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 | ||
| 第8行: | 第8行: | ||
基础数据类型不具备对象属性{{qm|是不是叫对象属性}}。 | 基础数据类型不具备对象属性{{qm|是不是叫对象属性}}。 | ||
{{ | {{Double-columns|<syntaxhighlight lang="javascript"> | ||
var foo = 'hello'; | var foo = 'hello'; | ||
foo = 'world'; | foo = 'world'; | ||
| 第34行: | 第34行: | ||
原始类型被强制转换成 <code>String</code> 类型: | 原始类型被强制转换成 <code>String</code> 类型: | ||
{{ | {{Double-columns|<syntaxhighlight lang="javascript"> | ||
'1'.toString();</syntaxhighlight> | '1'.toString();</syntaxhighlight> | ||
|{{Consoleout|<pre>"1" | |{{Consoleout|<pre>"1" | ||
| 第42行: | 第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> | ||
2026年11月26日 (四) 05:08的最新版本
引言
基本数据类型存储的是值,值不可调用。
undefined.toString();
Uncaught TypeError: Cannot read property 'toString' of undefined at <anonymous>:1:11
属性
基础数据类型不具备对象属性?(是不是叫对象属性) 。
var foo = 'hello';
foo = 'world';
console.log(foo);
foo.bar = 1234;
console.log(foo.bar);
'world' undefined
精度
IEEE 754 规定64位:
- 符号位:1位
- 指数:11位
- 有效 精度:53位(显式存储52位)

库
- bignumber
检测
String(Number('1152921504735848759'))=='1152921504735848759
强制转换类型
原始类型被强制转换成 String 类型:
'1'.toString();
"1"
浮点数 BUG
原始类型 Number 属于浮点数类型。
0.1 + 0.2
0.1 + 0.2 !== 0.3
0.30000000000000004 true
疑点
有人传言闭包中的基本数据类型变量不保存在栈内存中,而是保存在堆内存中?(未确定) ,有待考证。
No categories