【问题标题】:I am a beginner i JavaScript and i can't see why this is showing an error in Brackets in ESLint section我是 JavaScript 的初学者,我不明白为什么在 ESLint 部分的括号中显示错误
【发布时间】:2021-02-11 22:02:56
【问题描述】:

var firstName = 'John';
    console.log(firstName);
    This is leaves an error saying:
    ERROR: Unexpected console statement.[no-console]  
    ERROR: 'console' is not defined.[no-undef]

我尝试重启应用并重写代码,但每次仍然显示相同的错误。

【问题讨论】:

  • no-console 的 eslint 规则只是告诉您删除生产代码的 console.log 语句。
  • 无控制台请阅读 eslint 文档

标签: javascript eslint


【解决方案1】:

这些是 ESLint 错误/警告,而不是 JavaScript 错误/警告。它们引用了hereno-consoleno-undef)列出的规则。

来自no-console

规则详情

此规则不允许调用console 对象的方法。

您正在使用 console 对象,因此 ESLint 告诉您您违反了该规则。

来自no-undef

规则详情

对未声明变量的任何引用都会导致警告,除非该变量在 /*global ...*/ 注释中明确提及,或在配置文件中的 globals 键中指定。

您问题中的错误详细信息表明这与 console 变量有关。我很惊讶console 不是在您运行它的环境中声明的变量,因为它在所有通常的环境(浏览器、Node.js)中都是如此,但显然是这样。

【讨论】:

    猜你喜欢
    • 2018-12-06
    • 2022-01-08
    • 2022-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-06
    • 2019-06-26
    • 1970-01-01
    相关资源
    最近更新 更多