Essential JavaScript


Try running this code in the practice editor:

1 + 2
3 + 5 - 1
// 55 / 11

The result is 7. Notice how this code is almost identical to the code in a previous lesson, but with one key difference.

The // in front of that third line marks the rest of the line as a comment. JavaScript ignores comments. They are a way for developers to write notes in the code.

We can also use comments to tell JavaScript to ignore lines of code while we are working and we want to test something. You can put // in front of a line and JavaScript will ignore it.

Since JavaScript ignored the 55 / 11 expression, the last expression it ran was 3 + 5 - 1. That's why 7 came back as our result.

Multiline Comments

We can also comment out multiple lines like this:


Everything between /* and */ is a comment.

The above code will only log 1 and 4 because the rest of the code is just a comment.

We can use this kind of comment in the middle of a line as well:

console.log(1, 2, /* 3, */ 4);

The above code won't log 3 because it has been commented out.

Learning Goals

Code Editor