Node.js code and let pass it with Eslint(Rule figuration - version 6) https://es
ID: 3729184 • Letter: N
Question
Node.js code and let pass it with Eslint(Rule figuration - version 6)
https://eslint.org/demo
========================
'eslint -c .eslintrc.js sum.js'
'use strict'
let total = 0;
const cmds = process.argv;
for (let i = 2; i < cmds.length; i++) {
total += cmds[i] - 0;
}
console.log("The total is" + total + "!");
===================================
Correct 3 errors
Messages Fixed Code 4:14 -'process' is not defined. (no-undef) 9:1 - Unexpected console statement. (no-console) 9:1- 'console' is not defined. (no-undef)Explanation / Answer
To fix error 1, i.e., 'process' is not defined, you need to include the global environment variable "process" under "env" inside eslintrc.js file. "env" includes all the global variables which can be used in your code. "env": { ............ "process": true, ............ }, Error 2: Unexpected Console statement is happening because ESlint does not allow console logging. To enable console logging, you need to modify your eslintrc.js to include the following block of code. module.exports = { rules: { 'no-console': 'off', }, }; To resolve error 3: 'console' is not defined, you need to have both browser and node defined in your eslint config under "env". "env": { ............ "node": true, "browser": true, ............ },
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.