Comments
Comments explain code and are ignored when the program runs.
Syntax
// single line
/* multi
line */Comments are notes in your code that JavaScript ignores. Use them to explain what your code does.
Two styles
- Single-line: everything after
//is a comment. - Multi-line: everything between
/*and*/is a comment.
Example
Loading editor…
Press Run to execute the code.
When to use it
- Explain a complex regex pattern inline so the next developer understands its purpose.
- Temporarily disable a block of debug-only console.log calls without deleting them.
- Document function parameters and return values with JSDoc-style block comments for IDE tooltips.
More examples
Inline single-line comment
Uses a single-line comment to add context next to a magic-number constant.
const TAX_RATE = 0.08; // 8% sales tax – update per jurisdictionBlock comment disables code
Wraps debug statements in a block comment so they are ignored at runtime but remain easy to re-enable.
/*
console.log("debug: raw payload", payload);
console.log("debug: headers", headers);
*/
processPayload(payload);JSDoc block comment
Adds a JSDoc block comment that documents parameters and return type for IDE tooling and generated docs.
/**
* Calculates the discounted price.
* @param {number} price - Original price in USD.
* @param {number} discount - Discount as a decimal (e.g. 0.1 for 10%).
* @returns {number} Final price after discount.
*/
function applyDiscount(price, discount) {
return price * (1 - discount);
}
Discussion