Interview Questions

JavaScript Comments

You write some code today and it makes perfect sense. But come back a month later, and you might have no idea what it does. Now imagine another person reading it for the first time. That's why we use comments.

Comments are notes you write inside your code that JavaScript completely ignores. They don't run. They don't affect anything. They're just there to help humans understand what's going on. JavaScript has two types:

  • Single-line comments
  • Multi-line comments

Good comments make your code readable, especially in larger projects. They help other developers (and future you) understand what the code does, why it exists, and how it works. They're essential for teamwork.

Read about Comment Coding Guidelines

A single-line comment starts with //. Everything after those two slashes on that line is ignored by JavaScript. Use these for quick notes next to your code.

javascript

//This is a signle line comment 

Multi-line comments let you write notes that span several lines. Start with /* and end with */. Everything in between is ignored.

javascript

/*
This is a multiline comment.
It's super useful for longer explanations
or temporarily "turning off" chunks of code.
*/ 

Multi-line comments are useful for longer explanations or for temporarily disabling a block of code without deleting it.

  • Comments are notes in your code that JavaScript ignores. They help explain what your code does.
  • Single-line: Start with //. Good for short notes.
  • Multi-line: Wrap with /* */. Good for longer explanations or disabling code blocks.
  • Comments make your code easier to read, maintain, and collaborate on.

What's next? Now that you know how to document your code clearly, let's look at popup boxes in the next tutorial.

lecture javascript
SimplyJavaScript Logo
Identifiers And Comments
lecture javascript
SimplyJavaScript Logo
Identifiers And Comments