From 6ca84f1794af830ada9736d7289ce29aabb04ca3 Mon Sep 17 00:00:00 2001 From: t7yang Date: Mon, 10 Jan 2022 08:38:05 +0800 Subject: remove `notranslate` class in zh-TW --- .../reference/statements/if...else/index.html | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'files/zh-tw/web/javascript/reference/statements/if...else') diff --git a/files/zh-tw/web/javascript/reference/statements/if...else/index.html b/files/zh-tw/web/javascript/reference/statements/if...else/index.html index a9317aa8a6..9224af1894 100644 --- a/files/zh-tw/web/javascript/reference/statements/if...else/index.html +++ b/files/zh-tw/web/javascript/reference/statements/if...else/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Statements/if...else

語法

-
if (條件式)
+
if (條件式)
    statement1
 [else
    statement2]
@@ -39,7 +39,7 @@ translation_of: Web/JavaScript/Reference/Statements/if...else
 
 

多重的 if...else 陳述式可以使用 else if 子句來建立一個巢狀結構的句子。要記住,在JavaScript中沒有 elseif (一個單字) 的語法可以用。

-
if (condition1)
+
if (condition1)
    statement1
 else if (condition2)
    statement2
@@ -52,7 +52,7 @@ else
 
 

將巢狀結構適當的排版後,我們能更了解其背後運作的邏輯:

-
if (condition1)
+
if (condition1)
    statement1
 else
    if (condition2)
@@ -64,7 +64,7 @@ else
 
 

如果在一個條件式中有多個陳述要執行,可以使用區塊陳述式({ ... }) 把所有陳述包在一起。 通常來說,無論如何都使用區塊陳述式是個很好的習慣,尤其是當你使用巢狀結構的 if 陳述式時,這會讓人更容易理解你的程式碼。

-
if (condition) {
+
if (condition) {
    statements1
 } else {
    statements2
@@ -73,7 +73,7 @@ else
 
 

不要被Boolean物件中,布林值的 truefalse 給混淆了。任何值只要不是 falseundefinednull0NaN,或者空字串 (""),並且任何物件,包括其值是 false的布林物件 ,仍然會被條件陳述式視為條件成立。舉例而言:

-
var b = new Boolean(false);
+
var b = new Boolean(false);
 if (b) // this condition is truthy
 
@@ -81,7 +81,7 @@ if (b) // this condition is truthy

使用 if...else

-
if (cipher_char === from_char) {
+
if (cipher_char === from_char) {
    result = result + to_char;
    x++;
 } else {
@@ -93,7 +93,7 @@ if (b) // this condition is truthy
 
 

要記得JavaScript沒有 elseif 可以使用。不過,你可以使用 elseif中間夾著空白的語法:

-
if (x > 5) {
+
if (x > 5) {
  /* do the right thing */
 } else if (x > 50) {
  /* do the right thing */
@@ -105,14 +105,14 @@ if (b) // this condition is truthy
 
 

建議不要在條件表達式中直接對物件賦值,因為這會使人在瀏覽程式碼時很容易將賦值( assignment )與相等( equality )混淆。舉例而言,不要使用以下寫法:

-
if (x = y) {
+
if (x = y) {
    /* do the right thing */
 }
 

如果你必須在條件表達式中使用賦值,最好ˇ的作法是以額外的括號包住賦值語句,如下所示:

-
if ((x = y)) {
+
if ((x = y)) {
    /* do the right thing */
 }
 
-- cgit v1.2.3-54-g00ecf