DEV Community

Cover image for How to use JavaScript Comments
Oloyede Adeosun
Oloyede Adeosun

Posted on • Updated on

How to use JavaScript Comments

Fun Facts About Javascript

Brendan Eich created JavaScript in 1995, and it became an ECMA standard in 1997. The standard's official name is ECMA-262. The language's official name is ECMAScript.

In this post, I will be looking at comments and how they are used in javascript. Lets get started!

What are comments in javaScript

In JavaScript, comments are used to provide annotations to your code to help anyone trying to read it understand it. They can also be used to deactivate sections of code without deleting them.

Comments are made by putting // before a single line or /* before and */ after several lines of codes.A variety of computer languages include the ability to comment on code as a standard feature.

Single Line Comment

Single-line comments in javascript are used to comment a portion of a line or a whole line of code. You can use it to either explain or debug the code (commenting out to stop the browser from reading the executing the line of code). I've provided an example of a before and after commenting out a line of code below:

Before comment

After comment

To comment out a line of code on Mac:
Select the line of code
On your keyboard, press the command and / keys together
Its the same on windows, the only difference is instead of command button it will be control on windows.

Multi-Line Comment

Comments that span multiple lines begin with /* and conclude with /. JavaScript will ignore any text between /* and */. To clarify the code, the example below uses a multi-line remark:

Multi-Line comment

Thanks for reading!

Top comments (0)