Step 3: Comments

Sometimes you might want to make a note for yourself in your code. Comments can be helpful for remembering logic and terminology, and make your code easier to understand for other people.

Try it out

To create a single line comment in JavaScript, you place two slashes // in front of the code or text. When you place these two slashes, all text to the right of them will be ignored, until the next line.

For example, here's a comment on the line above some code:

// checking type of hello world
console.log(typeof 'Hello world!');

You can even put comments on the same line as actual code:

console.log(typeof 'Hello world!'); // checking type of hello world

Mini challenge

Add some helpful comments to the code you wrote in the last step. Run the code and make sure you haven't broken anything!

Last updated