Remove console.log calls from JavaScript before you ship

Paste JavaScript and the tool deletes console.log, console.debug and console.info statements, or any console method you pick, without touching the same text inside strings or comments.

Live demo · real result from this tool

Cleaned code

function save(user) {  const ok = db.put(user);  if (!ok) console.error('save failed');  return ok && void 0 || ok;}const msg = "console.log('inside a string stays')";
Statements removed2
Replaced with void 0
1

Processed on your device — nothing is uploaded.

How to use the console.log remover

  1. Paste your code into the JavaScript box.
  2. Choose which calls to remove with the log, debug, info, warn and error boxes, or tick Every console method.
  3. Copy the Cleaned code or download it.
  4. Check the stats: Statements removed counts deleted calls, and Replaced with void 0 counts calls that had to stay as an expression.

What it does and when to use it

Debug logging piles up while you build a feature. Before a release, a code review or sharing a snippet, those calls leak data into the browser console and add noise for other developers. This tool removes them in one pass while leaving real error reporting in place, if you keep warn and error unticked.

It pairs well with the other clean-up tools. The JS comment remover strips comments the same careful way, and the JavaScript minifier shrinks the result. To see what your logs print before you delete them, try the JS console simulator.

How it works

The code is split into tokens by a lexer that understands strings, template literals, regular expressions and comments, so "console.log(1)" inside a string is never seen as a call. For each console.method( the tool finds the matching closing bracket, even across many lines. Then:

  • If the call starts a statement, the call and its semicolon are removed. If nothing else is on that line, the whole line goes.
  • If the call is part of an expression, it is replaced with void 0 so the code stays valid.
  • If something is chained after it, or it is a property such as logger.console.log, it is left alone.

Worked examples

Default settings.

function save(user) {
  console.log('saving', user);
  const ok = db.put(user);
  if (!ok) console.error('save failed');
  console.debug("done");
  return ok && console.info('saved') || ok;
}

becomes:

function save(user) {
  const ok = db.put(user);
  if (!ok) console.error('save failed');
  return ok && void 0 || ok;
}

Two statements were removed and one call became void 0. The error call stays because error was not ticked.

Text inside a string. In const tip = "use console.log(x) to debug"; the string is kept exactly. Only the real console.log(tip); line on the next row is removed.

Arrow function body. With warn also ticked, items.forEach(i => console.log(i)); becomes items.forEach(i => void 0); and the console.warn('slow'); line is removed.

Limits and tips

  • Aliases are not traced. const log = console.log; log(x) or window.console.log are not recognised.
  • Arguments go too. If an argument had a side effect, such as console.log(i++), that effect is removed with the call.
  • Empty blocks may remain. if (debug) { console.log(x); } leaves an empty if (debug) { } block, which is harmless but worth tidying.

Frequently asked questions

Why is a call replaced with void 0 instead of deleted?
When a console call sits inside an expression, such as after if (bad) without braces or inside a && b, deleting it would leave broken code. void 0 is an expression that does nothing and returns undefined, which is what console.log returns anyway.
Which methods are removed by default?
log, debug and info. warn and error stay unticked because those messages are often wanted in production. Tick "Every console method" to remove table, time, group, assert, trace and the rest as well.
Will it break code that uses the return value of console.log?
Calls followed by .then, a further call or square brackets are left alone, so chained code is not damaged. Plain calls inside expressions become void 0, which returns the same undefined.
Should I use this or a build setting?
For a one-off clean-up this is quick. In a project, a minifier option such as Terser's drop_console or a lint rule like ESLint's no-console catches new calls every time you build.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close