JavaScript

JavaScript

By DeepSource

Avoid using `console` in code that runs on browserJS-0002

Bug risk
Has Autofix

It is considered a best practice to avoid the use of any console methods in JavaScript code that will run on the browser.

Usually, console methods are only used for debugging, and can leak internal info to the client. Removing the console call will fix this issue.

Examples

Bad Practice

if (foo()) {
  // perform action
  console.log("Log a debug level message.");
}

if (hasError()) {
  console.error("message")
}

Recommended

if (foo()) {
  // perform action
}

if (hasError()) {
  throw new Error("message")
}