Skip to content

Commit 0510d99

Browse files
author
howardchi
committed
finished types/ casting.md, typeof.md
1 parent 7b6fb69 commit 0510d99

File tree

2 files changed

+21
-28
lines changed

2 files changed

+21
-28
lines changed

doc/zh-TW/types/casting.md

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,49 +16,44 @@ JavaScript 是一個 *弱類型* 的程式語言,所以在 **任何** 情況
1616
10 == 010;
1717
10 == '-10';
1818

19-
> **ES5 Note:** Number literals that start with a `0` are interpreted as octal
20-
> (Base 8). Octal support for these has been **removed** in ECMAScript 5 strict
21-
> mode.
22-
>
19+
> **ES5 注意:** 如果數字字面值的開頭是 `0` 它會強制轉為八進位數字解析。
20+
> 而在 ES5 嚴格模式下,它已經被刪除了。
2321
2422

2523
To avoid the issues above, use of the [strict equal operator](#types.equality)
2624
is **highly** recommended. Although this avoids a lot of common pitfalls, there
2725
are still many further issues that arise from JavaScript's weak typing system.
26+
為了去避免上驗的事件發生,我們會用 [嚴格等於操作符](#types.equality) 這是強烈建議。
27+
因為它可以避免很多常見的問題,但 JavaScript 的弱類型系同仍然會導致一些其他問題。
2828

29-
### Constructors of Built-In Types
29+
### 內置類型的建構函式
3030

31-
The constructors of the built in types like `Number` and `String` behave
32-
differently when being used with the `new` keyword and without it.
31+
內置類型(比如 `Number``String`)在被調用時,使用或不使用 `new` 的結果完全不同。
3332

3433
new Number(10) === 10; // False, Object and Number
3534
Number(10) === 10; // True, Number and Number
3635
new Number(10) + 0 === 10; // True, due to implicit conversion
3736

38-
Using a built-in type like `Number` as a constructor will create a new `Number`
39-
object, but leaving out the `new` keyword will make the `Number` function behave
40-
like a converter.
37+
使用內置類型 `Number` 作為建構函式會建造一個新的 `Number` 物件,而在不使用 `new` 關鍵字的 `Number` 函式更像是一個數字轉換器。
4138

42-
In addition, passing literals or non-object values will result in even more
43-
type coercion.
39+
另外,在比較中引入物件的字面值會導致更加複雜的強制類型轉換。
4440

45-
The best option is to cast to one of the three possible types **explicitly**.
41+
最好的方式是比較值的 **顯示** 的轉換成最有可能的三種形態
4642

47-
### Casting to a String
43+
### 轉換成字符串
4844

4945
'' + 10 === '10'; // true
5046

51-
By prepending an empty string, a value can easily be cast to a string.
47+
將一個值加上空字符串可以輕鬆轉為字符串類型。
5248

53-
### Casting to a Number
49+
### 轉換成一個數字
5450

5551
+'10' === 10; // true
5652

57-
Using the **unary** plus operator, it is possible to cast to a number.
53+
使用 **一元** 的加號操作符,可以把字符串轉為數字。
5854

59-
### Casting to a Boolean
60-
61-
By using the **not** operator twice, a value can be converted a boolean.
55+
### 轉換成一個 Bool
56+
通過使用 **** 操作符兩字,可以把一個值轉換為 Bool。
6257

6358
!!'foo'; // true
6459
!!''; // false

doc/zh-TW/types/typeof.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
## The `typeof` Operator
1+
## `typeof` 操作符
22

3-
The `typeof` operator (together with
4-
[`instanceof`](#types.instanceof)) is probably the biggest
5-
design flaw of JavaScript, as it is almost **completely broken**.
3+
`typeof` 操作符 (和
4+
[`instanceof`](#types.instanceof)) 可能是最大的設計錯誤在 JavaScript,因為它幾乎不可能從它們那裡得到想要的結果。
65

7-
Although `instanceof` still has limited uses, `typeof` really has only one
8-
practical use case, which does **not** happen to be checking the type of an
9-
object.
6+
雖然 `instanceof` 還是有一些限制上的使用, `typeof` 只有一個實際上的運傭情形,但是 **不是** 用在檢查物件的類型。
107

118
> **Note:** While `typeof` can also be called with a function like syntax, i.e.
129
> `typeof(obj)`, this is not a function call. The parentheses behave as normal
1310
> and the return value will be used as the operand of the `typeof` operator.
1411
> There is **no** `typeof` function.
1512
16-
### The JavaScript Type Table
13+
14+
### JavaScript 類型表格
1715

1816
Value Class Type
1917
-------------------------------------

0 commit comments

Comments
 (0)