Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Using Comments to Document Code | JavaScript Fundamentals
/
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?

正しい答えを選んでください

question mark

How do we create a single-line comment?

正しい答えを選んでください

question mark

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

正しい答えを選んでください

question mark

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

正しい答えを選んでください

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 1.  4

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 1.  4
some-alt