我将所有内容都放在括号中,但下面的代码仍然在 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) 形式,因为(我想)&&|| 是否优先并不是很明显。修复它看起来像 if(a && b && (c || d)),它会停止提示。

关于javascript - 如何修复 jslint '&&' 子表达式应包含在括号错误中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7570868/

10-13 05:40