What Are Comments in Coding? (Explained for Beginners)

Most beginners read a line of code and think every single part of it does something. I thought the same thing when I first started. Then I saw // in someone’s code and spent ten minutes trying to figure out what it did.

Turns out — the computer ignores it completely.

Comments are one of the simplest concepts in coding. In this guide, I will explain exactly what they are, why every developer uses them, and how to write them correctly from day one.

What Are Comments in Coding?

💬
Simple Definition

A comment is a line you write inside your code that the computer completely ignores. It is a note — written by you, for you or anyone else reading the code. Zero effect on how the program runs.

Comments Meaning in Plain English H3

Think of comments as sticky notes inside your code. When I first saw // in someone’s program, I thought it was part of the logic. It was not. It was just a note the developer left for themselves — and the computer skipped right past it. Comments explain the “why” behind your code, not the “what.” That one difference is everything.

📖
Real-life analogy: Comments are like writing notes in the margin of a textbook. The notes do not change the content — they just help you understand it better when you come back later.

How the Computer Treats Comments H3

When your program runs, the computer reads line by line — top to bottom. The moment it spots a comment, it skips it without hesitation. No error. No slowdown. No processing. Your code runs exactly the same — with or without comments.

how-computer-reads.js
let name = “Sara”;
✓ Runs
// This stores the user’s name
✗ Skipped
let age = 25;
✓ Runs
// Age must be above 18 to register
✗ Skipped
console.log(name);
✓ Runs

Types of Comments in Coding

There are three types of comments most beginners need to know. Pick the tab below and read through each one — they are simpler than they sound.

Single-Line
Multi-Line
Inline
● Single-Line Comment

Single-Line Comments

This is the most common type. You write // and everything after it on that line becomes a comment. I use single-line comments every day — quick notes, reminders, short explanations. One line. Done.

Syntax → // Your comment here
// Calculate total price after discount let price = 100;
let discount = 0.2; // 20% off for premium users let total = price * (1 – discount);
💡 When to use it: Short notes, quick reminders, or explaining a single line of code.
● Multi-Line Comment

Multi-Line Comments

When one line is not enough, use /* to start and */ to end. Everything between them is a comment — no matter how many lines. Great for explaining a whole section of code before someone reads it.

Syntax → /* comment starts */ … /* ends */
/* This function calculates the final price after applying discount for premium users Rule set by the marketing team — May 2026 */ function getTotal(price) {
  return price * 0.8;
}
💡 When to use it: Before a function, a complex block, or when explaining a business rule.
● Inline Comment

Inline Comments

An inline comment sits on the same line as your code — right after it. It is perfect for adding a quick note without breaking the flow. Use them sparingly — too many make your code hard to read.

Syntax → code here; // note here
let maxRetries = 3; // max allowed login attempts let timeout = 5000; // 5 seconds in milliseconds console.log(maxRetries);
💡 When to use it: When a value or line needs a quick clarification right next to it.

Why Are Comments Important in Programming?

Some beginners skip comments — thinking they waste time. That changes the moment you open your own code two weeks later and have no idea what it does.

Reason 01
🧠

Comments Help You Remember Your Own Code

I once wrote a function, felt proud of it, and moved on. Three weeks later, I opened it and had no idea what it did. Code without comments is like notes without context. A single comment saves you minutes of confusion later.

“Future you will thank present you for every comment you write today.”
Reason 02
👥

Comments Make Code Easier for Others to Read

Coding is rarely a solo activity. Someone else will read your code — a teammate, a teacher, or a future developer. Good comments turn confusing code into readable code. They show you care about clarity, not just making things work.

“Code is read far more often than it is written.”
Reason 03
🐛

Comments Help You Fix Problems Faster

When something breaks, comments act like a map. They tell you what each part was supposed to do — so finding the broken piece takes seconds instead of hours. Good comments make debugging much less painful.

“A commented codebase is a debuggable codebase.”
💡
Simple rule: If you had to think for more than 5 seconds to write a line of code — leave a comment explaining it. Your future self will thank you.

How to Write Comments in Different Languages

The good news — once you learn how comments work in one language, the idea is the same everywhere. Only the symbols change. Click each language below to see exactly how it is done.

JavaScript and Java Comments
// single-line  ·  /* multi-line */
// /* */
▾

JavaScript and Java use the same comment symbols. // for a single line and /* */ for multiple lines. These are the most common symbols you will see — most C-based languages use them. If you learn these two, you already know half the languages out there.

// Single-line comment in JS
let score = 100;

/* Multi-line comment
Used for longer explanations */
console.log(score);
Python Comments
# single-line  ·  ”’ multi-line ”’
# ”’ ”’
▾

Python uses # for single-line comments — clean and simple. For multi-line, most developers use triple quotes ”’ ”’. Python’s comment style is one of the easiest to read — which is another reason it is the best first language for beginners.

# Single-line comment in Python
name = “Sara”

”’
Multi-line comment in Python
Useful for explaining a function
”’
print(name)
HTML and CSS Comments
<!– HTML –>  ·  /* CSS */
<!– –> /* */
▾

HTML uses <!– –> and CSS uses /* */. I use HTML comments to mark sections of a page clearly — especially when working with long files. These two together make web code much easier to read and manage.

<!– Navigation section –>
<nav></nav>

/* CSS: Main heading style */
h1 { color: #00c896; }
🎯
Key takeaway: The symbols differ — but the idea never changes. A comment is always a note for humans, ignored by the computer. Learn the symbol for your language and you are done.

When to Use Comments — and When NOT To

Comments are powerful — but only when used right. Too many comments clutter your code just as much as too few. Here is the simple rule I follow every day.

✅

Good Uses for Comments

Use comments when your code needs context that the code itself cannot give. A tricky formula, a business rule, a workaround — these are exactly when a comment earns its place.

✓ Good comment
// 0.2 = 20% tax rate set by finance team
let tax = price * 0.2;
✓ Good comment
// Retry up to 3 times before showing error
let retries = 3;
✓ Adds context — keep it
❌

Bad Comment Examples to Avoid

A bad comment states what the code already clearly shows. If anyone reading can see what the line does without a comment — the comment is just noise. Skip it.

✗ Useless comment
// Add 1 to count
count = count + 1;
✗ Useless comment
// Print the name
print(name)
✗ States the obvious — remove it
📏
The golden rule: Comment the “why” — never the “what.” If your code clearly shows what it does, a comment only adds clutter. If it does not — that is exactly when a comment is needed.

Commenting Out Code — A Useful Trick

This is one of those things no tutorial told me about early on — but every developer uses it daily. It is simple, practical, and saves you from deleting code you might need again.

💡

What is Commenting Out Code?

The Concept

Commenting out means turning a line of real code into a comment — so the computer skips it without you deleting it. I use this all the time when testing. You disable a line, check if the problem is gone, then bring it back in one click.

✗ Before — runs
sendEmail(user);
chargeCard(user);
✓ After — skipped
sendEmail(user);
// chargeCard(user);
🕐

When Should You Comment Out Code?

Use Cases

Comment out code when you want to test without deleting. It is also great for keeping old code nearby while writing a better version. Never delete code you are unsure about — comment it out first and decide later.

Debugging a bug Testing new logic Keeping old version Disabling a feature Safe experimentation
⚡
Pro tip: Most code editors let you comment out a line with one keyboard shortcut — Ctrl + / on Windows or Cmd + / on Mac. Try it right now in any editor.

Common Mistakes Beginners Make With Comments

I made all three of these mistakes when I started. Knowing them now will save you from picking up bad habits that are hard to break later.

Mistake 01
📝

Writing Too Many Obvious Comments

Beginners often comment every single line — even ones that explain themselves perfectly. This clutters your code and makes it harder, not easier, to read. If the code is already clear — stay silent.

// Add 1 to i
i ++;
// Print name
print(name);
Fix → Only comment when the “why” is not obvious from the code.
Mistake 02
🕰️

Never Updating Old Comments

You write a comment, change the code, but forget to update the comment. Now the comment says one thing and the code does another. Outdated comments are worse than no comments — they actively mislead anyone reading.

// Returns user age
function getUser() {
  return user; // returns full object now
}
Fix → Every time you change code — check if the comment needs updating too.
Mistake 03
🩹

Writing Comments Instead of Fixing Bad Code

Some beginners leave confusing code in place and write a long comment explaining why it is confusing. That is the wrong order. Fix the code first — then a short comment is enough, if needed at all.

// This is messy but works, don’t touch
let x = a+b*c/d–e;
Fix → Clean up the code first. Let clear code speak — use comments to add context only.
🎯
Simple habit to build: Before publishing any code, scan your comments — are they still accurate? Are they needed? Two questions. Thirty seconds. Cleaner code every time.

Frequently Asked Questions About Comments

Short, honest answers to the questions beginners ask most about comments in code.

Q 01

Do comments slow down my program?

⚡

No — not even slightly. The computer skips comments completely when running your code. They have zero effect on speed or performance. Write as many as you need without worrying about it.

✓ Zero performance impact
Q 02

What is an example of a comment in programming?

💬

Here is the same comment written in three common languages — the idea is identical, only the symbol changes.

// JavaScript — This stores the user’s name
let name = “Sara”;

# Python — This stores the user’s name
name = “Sara”

✓ Both comments ignored — code runs perfectly
Q 03

What should I comment in my code?

🎯

Simple rule — comment the “why,” not the “what.” If the code explains itself, stay quiet. If it does not — write a short note.

✓
Complex logic that is hard to read
✓
Business rules — like tax rates or limits
✓
Workarounds — explain why you did it that way
✓
Anything future-you might forget in two weeks
💡 Comment the why — skip the obvious
🚀
Still have a question about comments? Send it to us at BasicCodingConcepts.info — we reply to every genuine beginner question.