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> | ||