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

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

      1. <legend id='D7ceE'><style id='D7ceE'><dir id='D7ceE'><q id='D7ceE'></q></dir></style></legend>
        • <bdo id='D7ceE'></bdo><ul id='D7ceE'></ul>
      2. <tfoot id='D7ceE'></tfoot>

        Javascript &amp;&amp;运算符 as if 语句?

        Javascript amp;amp; operator as if statement?(Javascript amp;amp;运算符 as if 语句?)
      3. <legend id='rjhsr'><style id='rjhsr'><dir id='rjhsr'><q id='rjhsr'></q></dir></style></legend>

                <tbody id='rjhsr'></tbody>

              <small id='rjhsr'></small><noframes id='rjhsr'>

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

                  <bdo id='rjhsr'></bdo><ul id='rjhsr'></ul>
                  本文介绍了Javascript &amp;&amp;运算符 as if 语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  这应该是一个非常简单的问题,我只是在任何地方都找不到答案,所以我想节省一些时间在这里问.

                  This should be quite a simple question I just couldn't find the answer anywhere so thought I'd save myself some time and ask here.

                  我正在查看一些 javascript 代码并注意到以下形式的表达式:

                  I was looking at some javascript code and noticed an expression of the form:

                  a < b && (other maths statements);
                  

                  其他数学语句只是分配变量和简单的东西.

                  The other maths statements are just assigning of variables and simple stuff.

                  我的问题是这样的.这是编写紧凑 if 语句的另一种方式吗?

                  My question is this. Is this another way to write compact if statements?

                  我知道那个语句?if-block:else-block;是一种方法,但作为 &&是短路和左联想这就是我能想到的.我知道你不能使用这种方法设置 else 块,但它非常简洁.

                  I know that statement?if-block:else-block; is one way to do it but as && is short-circuit and left-associative this is all I can think it would be. I know you can't have an else block with this method but it's pretty neat.

                  请有人验证一下我早上这个时候醒着吗?

                  Can someone just validate I'm awake at this time in the morning please.

                  谢谢,

                  推荐答案

                  是的,你可以做到.如果 a 小于 b 其他语句将被执行.

                  Yes, you can do it. If a is less than b the other statements are going to execute.

                  也就是说,你可能不应该这样做.与其尝试为自己节省少量的输入,不如使用更易读的代码,其目的是显而易见的.毕竟,如果您需要检查您没有误解它,其他可能需要阅读或修改您的代码的程序员可能会遇到同样的问题.

                  That said, you probably shouldn't do it. Rather than trying to save yourself a small amount of typing you should instead go with a more readable piece of code whose purpose is immediately obvious. After all, if you needed to check that you weren't misinterpreting it, other programmers who may have to read or modify your code could have the same problem.

                  如果您尝试执行多个分配,这也有一个陷阱,但中间分配之一是虚假"值.考虑这个例子:

                  There is also a pitfall with this if you were trying to do multiple assignments, but one of the middle assignments was for a "falsey" value. Consider this example:

                  a < b && (a = 1) && (b = 0) && (c = 3);
                  

                  本质上,如果 a 小于 b,则将 a 设置为 1, b 设置为 0 并且 c 为 3.但是,(b = 0) 返回 false(转换为布尔值时,0 被认为是 false),因此 (c = 3) 部分永远不会执行.显然,对于这个基本示例,任何对 JavaScript 有相当了解的人都可以计算出它会失败,但是如果 abc 来自其他地方,没有直接迹象表明它不会总是有效.

                  Essentially, if a is less than b, set a to 1, b to 0 and c to 3. However, the (b = 0) returns false (0 is considered false when converted to a boolean), so the (c = 3) part never executes. Obviously with that basic example anybody who is reasonably knowledgeable about JavaScript could work out that it will fail, but if the values for a, b and c were coming from elsewhere there'd be no immediate indication that it wouldn't always work.

                  这篇关于Javascript &amp;&amp;运算符 as if 语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 获取视频观看次数?)

                    <small id='2PQtF'></small><noframes id='2PQtF'>

                        <bdo id='2PQtF'></bdo><ul id='2PQtF'></ul>

                            <legend id='2PQtF'><style id='2PQtF'><dir id='2PQtF'><q id='2PQtF'></q></dir></style></legend><tfoot id='2PQtF'></tfoot>

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