Using 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
Comments are ignored by the interpreter and are helpful for documentation.
Single-line Comments (//)
Single-line comments ignore everything on the same line.
123console.log("Line 1"); // console.log("Line 2"); console.log("Line 3");
Only the commented-out line is skipped.
You can also comment multiple consecutive lines:
12345console.log("Line 1"); console.log("Line 2"); // console.log("Line 3"); // console.log("Line 4"); console.log("Line 5");
Or add a comment at the end of a line:
123console.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");
Multi-line Comments (/* ... */)
Use multi-line comments when you want to disable larger sections of code.
1234567891011console.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");
Everything between /* and */ is ignored.
Multi-line comments can also hide part of a line:
123console.log("Part 1", /* "Part 2", */ "Part 3"); /* console.log("Part 4"); */ console.log("Part 5");
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?
すべて明確でしたか?
フィードバックありがとうございます!
セクション 1. 章 4
AIに質問する
AIに質問する
何でも質問するか、提案された質問の1つを試してチャットを始めてください
セクション 1. 章 4