A comment is text in your code that the computer ignores completely — it's there for humans, not the machine. Comments explain *why* code does something, especially anything that isn't obvious from the code itself.
// This calculates the total price including tax
let total = price * 1.18;/*
This function validates a user's age.
It returns true only if the age is a realistic human age.
*/
function isValidAge(age) {
return age > 0 && age < 130;
}Good code with clear variable and function names often needs very few comments — the code explains itself. Comment when the *why* isn't obvious: a workaround for a bug, a non-obvious business rule, or a warning about something easy to break.
A comment that just restates the code adds noise, not value: // add 1 to x above x = x + 1; tells you nothing you couldn't already see.