gpt4 book ai didi

javascript - JS 构建错误,Lint 错误无常量条件

转载 作者:行者123 更新时间:2023-12-02 10:52:36 25 4
gpt4 key购买 nike

尝试构建此代码时,我收到错误 Unexpected constant condition no-constant-condition。 (错误在线用 >>> 指示)
代码运行用户输入,commandVariable0 & commandVariable1 从输入中获取数据,在本例中为 b2b 上 b2b 关闭 , 如果他们用户应该输入 b2b测试那么它应该给出错误警告:commandVariable1 is not a valid settings option。
如果用户输入 ,谁能帮我理解为什么这不起作用b2b测试它认为它是有效的。
任何帮助都将不胜感激。

const b2b = function(data)
{
const commandVariable0 = data.cmd.params.split(" ")[0].toLowerCase();
const commandVariable1 = data.cmd.params.split(" ")[1].toLowerCase();

>>> if (commandVariable1 === "on"||"off")
{
b2bvar = commandVariable1;
var output =
"**```Bot 2 Bot Command Here```**\n" +
`Embeded Messages : ${b2bvar}\n\n` +
`Command Variable 0 : ${commandVariable0}\n` +
`Command Variable 1 : ${commandVariable1}\n`;

data.color = "info";
data.text = output;
return botSend(data);
}

data.color = "error";
data.text =
":warning: **`" + commandVariable1 +
"`** is not a valid settings option.";
return botSend(data);
};
请忽略草率的代码。

最佳答案

改变你的线路if (commandVariable1 === "on"||"off")if (commandVariable1 === "on" || commandVariable1 === "off") 有什么问题?
在上述行中,JavaScript 将首先检查 commandVariable1等于 "on"如果不是,那么它将转换 "off"转换为 bool 值并检查是否为真。
由于字符串 "off"是一个常数,总是会导致 true在 JavaScript 中,你的 linter 会提示不必要的 OR 条件。

关于javascript - JS 构建错误,Lint 错误无常量条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63873577/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com