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):

// This prints a greeting print("Hello")

Everything after // on that line is ignored.

Multi-line comment

Example:

/* This function calculates the total price */

Used for longer explanations.

Comments in different languages

Python:

# This is a comment

JavaScript / Java:

// This is a comment

Although syntax differs, the purpose is the same.

Good vs Bad comments

Good comment:

// Calculate final price including tax

Bad comment:

// Add numbers a = a + b

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

Source

Simplified from general programming documentation and Wikipedia.

Nach oben scrollen