A comment is text in your code that is ignored when the program runs. It’s meant for humans, not the computer.
Consider the following example:
Console.WriteLine("Hello, World!");
// This is a comment. It's ignored and not executed.
Console.WriteLine("Hello, Again!");print("Hello, World!")
# This is a comment. It's ignored and not executed.
print("Hello, Again!")console.log("Hello, World!");
// This is a comment. It's ignored and not executed.
console.log("Hello, Again!");The output of this program is:
Hello, World!
Hello, Again!The comment has no effect on the program, it’s completely ignored.
Comments are useful for explaining code that isn’t immediately clear. They help others understand your code, and they help you when you come back to it later.
Use comments when they add clarity. Avoid them when the code is already obvious.