“unexpected console statement no-console”

二次信任 提交于 2020-02-02 11:17:08

问题


I'm getting this error in Brackets.

I want to stress the fact that it's literally the second time I opened a JS file. As I stressed It I want also to emphasize the fact that I have no clue what Eslint and node.js are.

All the fixes on the StackOverflow and other sites assume knowing how abovementioned entities work.

Please help to a complete newb to fix the problem and learn something new.

Thank you in advance!

Here's the piece of code, but I don't think it will help with anything.

Html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JavaScript</title>

</head>
<body>
<h1>Javascript starter</h1>

    <script src=Script.js> </script>
</body>
</html>

Javascript:

var now = 2018;
var yearJohn = 1989;
var fullAge = 18;

//Multiple operators
var isFullAge = now - yearJohn >= fullAge; //true
сonsole.log(isFullAge);

//Grouping

    var ageJohn = now - yearJohn;
    var ageMark = 35;
    var average = (ageJohn + ageMark)/2;
    console.log(average);

    // Multiple assigments
    var x, y;
    x = y = (3 + 5) * 4 - 6; // 8 * 4 - 6 // 32 - 6 // 26

    console.log(x, y);

    // More operators
    x *= 2;
    console.log(x);
    x += 10;
    // eslint-disable-next-line no-console
    console.log(x);

回答1:


If it really is ESLint that is causing errors for this change, you can fix it by disabling the rule for that particular line:

// eslint-disable-next-line no-console
console.log(isFullAge);



回答2:


Just add "no-console": 0 to the rules part of .eslintrc.js file.

E.g.

"rules": {
    "no-console": 0
},



回答3:


Please try to change console.log to document.write

and then open your html file in browser

var now = 2018;
var yearJohn = 1989;
var fullAge = 18;

//Multiple operators
var isFullAge = now - yearJohn >= fullAge; //true
document.write(isFullAge);

//Grouping

var ageJohn = now - yearJohn;
var ageMark = 35;
var average = (ageJohn + ageMark)/2;
document.write(average);

// Multiple assigments
var x, y;
x = y = (3 + 5) * 4 - 6; // 8 * 4 - 6 // 32 - 6 // 26

document.write(x, y);

// More operators
x *= 2;
document.write(x);
x += 10;
// eslint-disable-next-line no-console
document.write(x);



回答4:


Add the following to your .eslintrc.js file

"no-console": ["error", { "allow": ["warn", "error"] }]


来源:https://stackoverflow.com/questions/56409975/unexpected-console-statement-no-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!