Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何修复'&&';子表达式应包装在parens错误中_Javascript_Jslint - Fatal编程技术网

Javascript 如何修复'&&';子表达式应包装在parens错误中

Javascript 如何修复'&&';子表达式应包装在parens错误中,javascript,jslint,Javascript,Jslint,我将所有内容都放在括号中,但下面的代码仍然在jslint中抛出错误: Problem at line 5 character 104: The '&&' subexpression should be wrapped in parens. if ((typeof (c1) === 'string') && (typeof (c2) === 'string') && (c1 !== n... 如何修复 "use strict"; functio

我将所有内容都放在括号中,但下面的代码仍然在jslint中抛出错误:

Problem at line 5 character 104: The '&&' subexpression should be wrapped in parens.

if ((typeof (c1) === 'string') && (typeof (c2) === 'string') && (c1 !== n...
如何修复

"use strict";

function t() {
    var c1, c2;
    if (((typeof (c1)) === 'string') && ((typeof (c2)) === 'string') && (c1 !== null) && (c2 !== null) && ((c1.trim()) === '') || ((c2.trim()) !== '')) {
        return;
    }
}

它抱怨形式
if(a&&b&&c||d)
,因为(我想)现在还不清楚
&
|
是否会优先。如果(a&&b&&(c | | d))它会停止抱怨。

我想它需要这样:

    if (((typeof (c1) === 'string') && (typeof (c2) === 'string') && (c1 !== null) && (c2 !== null)) && ((c1.trim()) === '') || ((c2.trim()) !== '')) {

将4个AND表达式包装在&&at 100的左侧。

我相当肯定您想要以下内容:

function t() {
    var c1, c2;
    if (typeof c1 === 'string' && typeof c2 === 'string' && c1 !== null && c2 !== null && (c1.trim() === '' || c2.trim() !== '')) {
        return;
    }
}
不是每个人都知道布尔逻辑的优先级,所以他们希望您将
c1.trim()| | c2.trim()
语句括在括号中,以便清楚地了解它们的操作方式


顺便说一句,我认为jslint希望运算符和操作数之间有空格是荒谬的。我认为当没有空格时会更清楚。

您是否尝试过…将'&&'-子表达式包装在parens中?这不是答案,但您可以在测试typeof.+1之前测试null来解释它,但您应该给出结果布尔值。既然你没有,我就提供了答案。