
Options
Paste JavaScript or TypeScript on the left and the same code without comments appears on the right as you type. The remover reads your code the way a JavaScript parser does, so // inside a URL string, a /* inside a regular expression, and text inside template literals and JSX are left exactly as written. It can keep license headers, JSDoc, and tool directives like // eslint-disable or /*#__PURE__*/, and it never changes what your code does. Nothing is uploaded; everything runs in your browser.
How to remove comments from JavaScript
- Paste your code into the left pane, or click Open file to load a .js, .mjs, .cjs, .jsx, .ts, or .tsx file. You can also drag a file onto the pane.
- Choose which comments to remove and which to keep. License comments are kept by default.
- Pick how blank lines are handled. Keep line numbers the same leaves an empty line wherever a comment was, so error messages and stack traces still point to the right line.
- Check the Removed tab to review every comment that was taken out. Click one to find it in your code.
- Click Copy, or Download to save the file with
.nocommentsadded to its name.
What gets removed and what stays
| In your code | Result |
|---|---|
count++; // add one | count++; |
/* block comment */ on its own lines | Removed, along with the lines it used |
a/* x */b | a b, so the two names don't run together |
"https://example.com" | Unchanged, because the slashes are inside a string |
/\/\/+/g (a regex) | Unchanged |
`Total: ${n /* items */}` | `Total: ${n}`. Only the comment inside ${ } is removed |
{/* JSX comment */} | Removed, including the braces |
/*! MIT License */ or @license | Kept unless you turn off License |
/** @param {string} id */ | Removed unless you turn on JSDoc |
// @ts-ignore, // eslint-disable-line, /* webpackChunkName: "x" */, /*#__PURE__*/ | Removed unless you turn on Tool directives |
#!/usr/bin/env node | Always kept. It's a hashbang, not a comment |
Why a simple find-and-replace breaks JavaScript
Most quick comment strippers use a regular expression like \/\/.*|\/\*[\s\S]*?\*\/. That pattern can't tell a comment from the same characters inside other code, so it breaks working programs in a few predictable ways:
- Strings:
const api = "https://example.com"becomesconst api = "https:, which won't run. - Regular expressions: a pattern such as
/[/*]/or/\/\//contains comment markers that aren't comments. - Template literals: text inside backticks is a string, but code inside
${ }can hold real comments. - JSX: in
<p>See http://example.com</p>the//is visible text on the page. - Division:
a / b / clooks like a regex to a careless tool.
This tool scans the code token by token instead. It tracks strings, template literals and their nested ${ } expressions, regex literals versus the division operator, and JSX elements, so only real comments are removed. It was tested by stripping hundreds of real library files and confirming the parsed program was identical before and after.
It also handles two less obvious cases. When a removed block comment sat between two words, as in return/**/value, a space is put back so they don't merge. When a multi-line block comment sat between two pieces of code, as in return /* ... */ value across lines, the line break is kept, because JavaScript's automatic semicolon insertion treats that comment as a line break and removing it would change what the function returns.
Should you remove comments before deploying?
For production builds, a minifier such as Terser, esbuild, or SWC already removes comments, and it also shortens names and whitespace. Use this tool when you want readable code without comments: sharing a snippet, pasting code into a question or an AI prompt, cleaning up a file before review, or shipping a small script where you don't run a build step.
Two kinds of comments are worth keeping. License headers marked with /*! or @license are often required by the library's license when you redistribute its code, and minifiers keep them for the same reason. Annotations like /*#__PURE__*/ and /* webpackChunkName */ change how bundlers treat your code, so turn on Tool directives if the file will go through a bundler afterward.
Comment types in JavaScript
| Syntax | Name | Typical use |
|---|---|---|
// text | Line comment | Short notes to the end of the line |
/* text */ | Block comment | Longer notes, or comments in the middle of a line |
/** text */ | JSDoc comment | Documentation and type hints read by editors and TypeScript |
/*! text */ | Preserved comment | License and copyright notices that minifiers keep |
/// <reference /> | Triple-slash directive | TypeScript references to other files or types |
{/* text */} | JSX comment | Comments inside JSX markup in React |
Frequently asked questions
Will removing comments break my JavaScript?
No. The tool only removes text the JavaScript parser treats as a comment. Strings, regular expressions, template literals, and JSX text stay the same, and spaces or line breaks are put back wherever removing a comment would join two tokens or change automatic semicolon insertion.
Does it work with TypeScript, JSX, and TSX?
Yes. TypeScript type annotations, generics, enums, and decorators pass through unchanged, and JSX comments written as {/* ... */} are removed along with their braces. Text inside JSX elements is never treated as a comment.
Can I keep license comments?
Yes, and that's the default. Comments that start with /*! or contain @license or @preserve are kept. Uncheck License under Keep to remove them as well.
What are tool directives?
They are comments that other tools read, such as // eslint-disable-next-line, // @ts-ignore, /// <reference>, /* webpackChunkName */, /*#__PURE__*/, and //# sourceMappingURL. Turn on Tool directives to keep them so linting, type checking, and bundling still behave the same.
How do I keep the original line numbers?
Set Blank lines to Keep line numbers the same. Each removed comment is replaced by empty space instead of being deleted with its line, so line 120 in the output is still line 120 in your original file.
Is this the same as minifying?
No. Minifying also removes whitespace and line breaks and often renames variables. This tool removes only comments, so the code stays readable and formatted the way you wrote it.
Is my code uploaded anywhere?
No. The comment remover runs entirely in your browser, and your code is never sent to a server. It works offline once the page has loaded.
