<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # JavaScript 中的真值和假值 > 原文: [https://howtodoinjava.com/typescript/truthy-and-falsy/](https://howtodoinjava.com/typescript/truthy-and-falsy/) 在 JavaScript 中,真值是等于布爾值`true`的表達式,而假值則是等于布爾值`false`的表達式。 與其他語言不同,`true`和`false`值不限于`boolean`數據類型和比較。 它可以具有許多其他形式。 讓我們了解什么使 JavaScript 中的真假表達式成為事實。 ## 假值 javascript 中共有 **6 個假值/表達式**。 我將使用此函數來檢查值是真值還是假值。 ```java function testTruthyFalsy (val) { return val ? console.log('truthy') : console.log('falsy'); } ``` 布爾‘`false`’ 顯然布爾值`false`是`false`。 ```java testTruthyFalsy (false); //Prints 'falsy' ``` 空字符串,即`''` 任何空字符串都將被求值為`false`。 ```java testTruthyFalsy (''); //Prints 'falsy' ``` `undefined` 任何`undefined`變量將等于`false`。 ```java var my_var = undefined; testTruthyFalsy (my_var); //Prints 'falsy' ``` `null` 任何`null`變量將等于`false`。 ```java var my_var = null; testTruthyFalsy (my_var); //Prints 'falsy' ``` `NaN` 結果為`NaN`(不是數字)的任何數值表達式都將等于`false`。 ```java testTruthyFalsy (NaN); //Prints 'falsy' ``` 數字零,即 +0 或 -0 任何結果為零(`+0`或`-0`)的數值表達式都將等于`false`。 ```java testTruthyFalsy ( 2 - 2 ); //Prints 'falsy' testTruthyFalsy ( 0 ); //Prints 'falsy' ``` ## 真值 除了上面列出的假值以外的任何表達式或值 - 被認為是真值。 例如: ```java function testTruthyFalsy (val) { return val ? console.log('truthy') : console.log('falsy'); } testTruthy(true); // truthy testTruthy(false); // falsy testTruthy(new Boolean(false)); // truthy (object is always true) testTruthy(''); // falsy testTruthy('Packt'); // truthy testTruthy(new String('')); // true (object is always true) testTruthy(1); // truthy testTruthy(-1); // truthy testTruthy(NaN); // falsy testTruthy(new Number(NaN)); // truthy (object is always true) testTruthy({}); // truthy (object is always true) var obj = { name: 'John' }; testTruthy(obj); // truthy testTruthy(obj.name); // truthy ``` 將我的問題放在評論部分。 學習愉快!
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看