Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Using Comments to Document Code | JavaScript Fundamentals
Quizzes & Challenges
Quizzes
Challenges
/
Introduction to JavaScript

bookUsing Comments to Document Code

Comments let you hide parts of your code from being executed. They are useful when you want to temporarily disable code or leave notes for yourself or other developers.

Note
Note

Comments are ignored by the interpreter and are helpful for documentation.

Single-line Comments (//)

Single-line comments ignore everything on the same line.

123
console.log("Line 1"); // console.log("Line 2"); console.log("Line 3");
copy

Only the commented-out line is skipped.

You can also comment multiple consecutive lines:

12345
console.log("Line 1"); console.log("Line 2"); // console.log("Line 3"); // console.log("Line 4"); console.log("Line 5");
copy

Or add a comment at the end of a line:

123
console.log("Part 1.1"); console.log("Part 1.2"); console.log("Part 2.1"); // console.log("Part 2.2") console.log("Part 3.1"); console.log("Part 3.2");
copy

Multi-line Comments (/* ... */)

Use multi-line comments when you want to disable larger sections of code.

1234567891011
console.log("Line 1"); console.log("Line 2"); /* console.log("Line 4"); console.log("Line 5"); console.log("Line 6"); console.log("Line 7"); console.log("Line 8"); console.log("Line 9"); */ console.log("Line 11");
copy

Everything between /* and */ is ignored.

Multi-line comments can also hide part of a line:

123
console.log("Part 1", /* "Part 2", */ "Part 3"); /* console.log("Part 4"); */ console.log("Part 5");
copy

1. Why are comments used in code?

2. How do we create a single-line comment?

3. What is the syntax for creating a multi-line comment?

4. If you have a large code block and enclose it within /* and */, what happens to the enclosed code?

question mark

Why are comments used in code?

Select the correct answer

question mark

How do we create a single-line comment?

Select the correct answer

question mark

What is the syntax for creating a multi-line comment?

Select the correct answer

question mark

If you have a large code block and enclose it within /* and */, what happens to the enclosed code?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 4

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

bookUsing Comments to Document Code

Swipe to show menu

Comments let you hide parts of your code from being executed. They are useful when you want to temporarily disable code or leave notes for yourself or other developers.

Note
Note

Comments are ignored by the interpreter and are helpful for documentation.

Single-line Comments (//)

Single-line comments ignore everything on the same line.

123
console.log("Line 1"); // console.log("Line 2"); console.log("Line 3");
copy

Only the commented-out line is skipped.

You can also comment multiple consecutive lines:

12345
console.log("Line 1"); console.log("Line 2"); // console.log("Line 3"); // console.log("Line 4"); console.log("Line 5");
copy

Or add a comment at the end of a line:

123
console.log("Part 1.1"); console.log("Part 1.2"); console.log("Part 2.1"); // console.log("Part 2.2") console.log("Part 3.1"); console.log("Part 3.2");
copy

Multi-line Comments (/* ... */)

Use multi-line comments when you want to disable larger sections of code.

1234567891011
console.log("Line 1"); console.log("Line 2"); /* console.log("Line 4"); console.log("Line 5"); console.log("Line 6"); console.log("Line 7"); console.log("Line 8"); console.log("Line 9"); */ console.log("Line 11");
copy

Everything between /* and */ is ignored.

Multi-line comments can also hide part of a line:

123
console.log("Part 1", /* "Part 2", */ "Part 3"); /* console.log("Part 4"); */ console.log("Part 5");
copy

1. Why are comments used in code?

2. How do we create a single-line comment?

3. What is the syntax for creating a multi-line comment?

4. If you have a large code block and enclose it within /* and */, what happens to the enclosed code?

question mark

Why are comments used in code?

Select the correct answer

question mark

How do we create a single-line comment?

Select the correct answer

question mark

What is the syntax for creating a multi-line comment?

Select the correct answer

question mark

If you have a large code block and enclose it within /* and */, what happens to the enclosed code?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 4
some-alt