1. <tfoot id='62qfu'></tfoot><legend id='62qfu'><style id='62qfu'><dir id='62qfu'><q id='62qfu'></q></dir></style></legend>
      <i id='62qfu'><tr id='62qfu'><dt id='62qfu'><q id='62qfu'><span id='62qfu'><b id='62qfu'><form id='62qfu'><ins id='62qfu'></ins><ul id='62qfu'></ul><sub id='62qfu'></sub></form><legend id='62qfu'></legend><bdo id='62qfu'><pre id='62qfu'><center id='62qfu'></center></pre></bdo></b><th id='62qfu'></th></span></q></dt></tr></i><div id='62qfu'><tfoot id='62qfu'></tfoot><dl id='62qfu'><fieldset id='62qfu'></fieldset></dl></div>

      • <bdo id='62qfu'></bdo><ul id='62qfu'></ul>

      1. <small id='62qfu'></small><noframes id='62qfu'>

        为什么 {} == false 评估为 false 而 [] == false 评估为 true?

        Why does {} == false evaluate to false while [] == false evaluates to true?(为什么 {} == false 评估为 false 而 [] == false 评估为 true?)
      2. <tfoot id='Vshlr'></tfoot>
            <tbody id='Vshlr'></tbody>

          1. <small id='Vshlr'></small><noframes id='Vshlr'>

          2. <i id='Vshlr'><tr id='Vshlr'><dt id='Vshlr'><q id='Vshlr'><span id='Vshlr'><b id='Vshlr'><form id='Vshlr'><ins id='Vshlr'></ins><ul id='Vshlr'></ul><sub id='Vshlr'></sub></form><legend id='Vshlr'></legend><bdo id='Vshlr'><pre id='Vshlr'><center id='Vshlr'></center></pre></bdo></b><th id='Vshlr'></th></span></q></dt></tr></i><div id='Vshlr'><tfoot id='Vshlr'></tfoot><dl id='Vshlr'><fieldset id='Vshlr'></fieldset></dl></div>

                <legend id='Vshlr'><style id='Vshlr'><dir id='Vshlr'><q id='Vshlr'></q></dir></style></legend>
                • <bdo id='Vshlr'></bdo><ul id='Vshlr'></ul>
                  本文介绍了为什么 {} == false 评估为 false 而 [] == false 评估为 true?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  为什么 {} == false 评估为 false[] == false 评估为 true在 JavaScript 中?

                  Why does {} == false evaluate to false while [] == false evaluates to true in javascript?

                  推荐答案

                  这是根据抽象等式比较算法:

                  {} == false                // step 7 {} == ToNumber(false)
                  {} == 0                    // step 9 ToPrimitve({}) == 0
                  "[object Object]" == 0     // step 5 ToNumber("[object Object]") == 0
                  NaN == 0                   // step 1.c.i
                  
                  [] == false                // step 7 [] == ToNumber(false)
                  [] == 0                    // step 9 ToPrimitve([]) == 0
                  "" == 0                    // step 5 ToNumber("") == 0
                  0 == 0                     // step 1.c.iii
                  

                  参考:ToNumber,ToPrimitive

                  因此,更喜欢使用严格比较.

                  And because of this, prefer to use strict comparison.

                  ToPrimitive 如何在比较过程中将对象转换为基元 的一些示例.默认情况下,将调用对象的 valueOf 方法,如果 valueOf 没有返回原始值,则调用 toString.对于 Date 对象,它会默认调用 toString.

                  Some examples how ToPrimitive converts objects to primitives during comparison. By default, the valueOf method of the object will be called, and then toString if valueOf doesn't return a primitive value. For Date objects it will call toString by default.

                  var obj = {};
                  obj.valueOf();        // Object { } // the object itself
                  obj.toString();       // "[object Object]"
                  
                  
                  obj.valueOf = function() { return 123; };
                  obj == 123; // true
                  
                  obj.toString = function() { return 'foo bar'; };
                  obj == 123; // false
                  obj == 'foo bar'; // true
                  
                  // Date object
                  
                  var date = new Date();
                  date.valueOf();        // 1421430720379
                  date.toString();       // "Fri Jan 16 2015 09:52:00 GMT-0800 (PST)"
                  
                  date == 1421430720379 // false
                  date == "Fri Jan 16 2015 09:52:00 GMT-0800 (PST)" // true
                  
                  date.toString = function() { return 'foo'; };
                  date == 'foo'; // true
                  

                  这篇关于为什么 {} == false 评估为 false 而 [] == false 评估为 true?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Pause youtube video, youtube api(暂停 youtube 视频,youtube api)
                  Youtube iframe api not triggering onYouTubeIframeAPIReady(Youtube iframe api 未触发 onYouTubeIframeAPIReady)
                  How can I stop a video with Javascript in Youtube?(如何在 Youtube 中停止使用 Javascript 的视频?)
                  How to call Greasemonkey#39;s GM_ functions from code that must run in the target page scope?(如何从必须在目标页面范围内运行的代码中调用 Greasemonkey 的 GM_ 函数?)
                  How do you mute an embedded Youtube player?(如何使嵌入式 Youtube 播放器静音?)
                  How to get number of video views with YouTube API?(如何使用 YouTube API 获取视频观看次数?)
                      <tbody id='8Tfw2'></tbody>

                      <bdo id='8Tfw2'></bdo><ul id='8Tfw2'></ul>
                    • <i id='8Tfw2'><tr id='8Tfw2'><dt id='8Tfw2'><q id='8Tfw2'><span id='8Tfw2'><b id='8Tfw2'><form id='8Tfw2'><ins id='8Tfw2'></ins><ul id='8Tfw2'></ul><sub id='8Tfw2'></sub></form><legend id='8Tfw2'></legend><bdo id='8Tfw2'><pre id='8Tfw2'><center id='8Tfw2'></center></pre></bdo></b><th id='8Tfw2'></th></span></q></dt></tr></i><div id='8Tfw2'><tfoot id='8Tfw2'></tfoot><dl id='8Tfw2'><fieldset id='8Tfw2'></fieldset></dl></div>

                      • <tfoot id='8Tfw2'></tfoot>

                            <legend id='8Tfw2'><style id='8Tfw2'><dir id='8Tfw2'><q id='8Tfw2'></q></dir></style></legend>

                            <small id='8Tfw2'></small><noframes id='8Tfw2'>