Comments
The full text of this chapter, to read or revisit. To practise, do the exercises.
▶ Do the exercisesExercise 1 — What Are Comments?
Comments are notes in your code. JavaScript ignores them completely - they're just for humans to read.
// This is a comment
console.log("This will run"); // This comment is ignoredComments help you: - Explain what your code does - Leave reminders for yourself - Temporarily disable code
Exercise 2 — Single-Line Comments
Single-line comments start with //
// Display my Codémon's name
console.log("Aquachu");
// This line is commented out and won't run
// console.log("Shadowchu");Everything after // on that line is ignored by JavaScript.
Exercise 3 — Multi-Line Comments
Multi-line comments start with /* and end with */
/*
This is a longer comment
that spans multiple lines.
*/
console.log("Pyrochu");
/* You can also use it on one line */
console.log("Florachu");Everything between /* and */ is ignored.
Exercise 4 — Spot the Valid Comment
Which is a valid single-line comment in JavaScript?
// This is my comment# This is my comment-- This is my comment/* This is my commentHint : Single-line comments in JavaScript use two forward slashes.
Exercise 5 — Add a Comment
Add a single-line comment to this code:
Hint : Single-line comments start with //
Exercise 6 — Ready?
Now that you know how to use console.log() and how to comment your code, you're ready to enter the weird but cool world of JavaScript!