Comment
A comment is a note written inside the code that is ignored by the computer. It is used to explain what the code does. Comments are for humans, not for machines.
Why comments are important
Comments help:
Explain complex logic
- Make code easier to read
- Help other developers understand the program
- Remind yourself what the code does
Well-written comments improve code clarity.
How comments work
Single-line comment
Example (JavaScript):
Everything after // on that line is ignored.
Multi-line comment
Example:
Used for longer explanations.
Comments in different languages
Python:
JavaScript / Java:
Although syntax differs, the purpose is the same.
Good vs Bad comments
Good comment:
Bad comment:
If the code is already obvious, comments may be unnecessary.
Why learning comments matters
Comments help you:
- Write professional code
- Work in teams
- Maintain large projects
- Document your logic
Readable code is as important as working code.
Simple example
Think of comments like sticky notes in a book. They explain important parts, but they do not change the story.
Related terms
- What is Parameter?
- What is Return Value?
- What is Scope?
Source
Simplified from general programming documentation and Wikipedia.