0% found this document useful (0 votes)
27 views1 page

Comments: Introduction To Javascript

Comments in JavaScript allow developers to annotate code for other programmers or future self. There are two types of comments - single line comments using // that comment out a single line, and multi-line comments using /* and */ that can comment multiple contiguous lines. Comments are ignored by the computer and exist only for human readers of the code.

Uploaded by

james hagrid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views1 page

Comments: Introduction To Javascript

Comments in JavaScript allow developers to annotate code for other programmers or future self. There are two types of comments - single line comments using // that comment out a single line, and multi-line comments using /* and */ that can comment multiple contiguous lines. Comments are ignored by the computer and exist only for human readers of the code.

Uploaded by

james hagrid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

INTRODUCTION TO JAVASCRIPT

Comments
Programming is often highly collaborative. In addition, our own code can quickly
become difficult to understand when we return to it— sometimes only an hour later! For
these reasons, it’s often useful to leave notes in our code for other developers or
ourselves.

As we write JavaScript, we can write comments in our code that the computer will ignore
as our program runs. These comments exist just for human readers.

Comments can explain what the code is doing, leave instructions for developers using
the code, or add any other useful annotations.

There are two types of code comments in JavaScript:

1. A single line comment will comment out a single line and is denoted with two
forward slashes // preceding it.
2. // Prints 5 to the console
console.log(5);
You can also use a single line comment to comment after a line of code:

console.log(5); // Prints 5
3. A multi-line comment will comment out multiple lines and is denoted with /* to
begin the comment, and */ to end the comment.
4. /*
5. This is all commented
6. console.log(10);
7. None of this is going to run!
8. console.log(99);
*/
You can also use this syntax to comment something out in the middle of a line of
code:

console.log(/*IGNORED!*/ 5); // Still just prints 5

You might also like