JavaScript Tutorials


» Introduction to JavaScript

» Practice IT Editor

» JavaScript Example

» JavaScript Placement

» JavaScript Syntax

» JavaScript Statements

» JavaScript Input

» JavaScript Output

» JavaScript Comments

» JavaScript Variables

» Variables' Scope

» JavaScript Operators

» JS Expressions & Concatenation

» JavaScript Data Type

» JavaScript Numbers

» Number Object

» JavaScript Strings

» String Object

» JavaScript Booleans

» Boolean Object

» JavaScript Functions

» JavaScript Arrays

» Array Object - Properties

» Array Object - Methods

» JavaScript Objects

» JavaScript Undefined

» JavaScript Nulls


» If Statement

» If Else Statement

» JavaScript Ternary Operator

» Switch Statement


» For Loops

» While Loops

» Break & Continue

» For...In Loops

» do...while Loop


» JavaScript Functions

» Creating Functions

» Functions' Parameters

» Functions' Arguments

» Function Invocation

» The Return Keyword

» The Arguments Object

» Callback Functions

» Arrow Functions


» JavaScript Arrays

» Creating Arrays

» Accessing Arrays

» Looping Arrays

» Multi - dimensional Arrays


» JavaScript Objects

» Creating Objects

» Prototype Definition

» Accessing Objects

» The this Keyword


» Introduction to AJAX


» Introduction to JSON


» The Date Object

» Date Methods

» Timing (SetInterval & SetTimeout)


» Math Object

» Math Methods


» DOM Introduction

» Accessing HTML Elements in DOM

» Get And Change Elements' Contents & Values

» Change Styling - DOM CSS

» DOM Attributes

» JavaScript Event Listeners

» DOM Event Listeners

» JS Events


» JS Strict Mode

» JavaScript Hoisting

» JavaScript let keyword

» Reserved Keywords

» JS Best Practices

» JavaScript vs ECMAScript


» JavaScript Calculator

.. » JavaScript » Introduction » JavaScript Comments
Share Tweet WhatsApp

JavaScript Comments

A JavaScript comment is any text, code and yes, just anything that should not be executed. When JavaScript programs and codes are being executed, comments are practically overlooked. EXAMPLE
//alert("Hello World"); This will not execute

/* var x = 5;
All of these will also not be executed */
Why Comments? You may wonder why you may want to write codes or statements that will not be executed but then, the concept is simple. You use comments to describe the complex tasks that you are having or solving in your program. This practice helps you and others, who may come across the codes, in the future to understand what you did. You can also use comments to "comment out" codes you believe are causing errors or codes you don't want to use anymore instead of outrightly deleting them. Must I Write Comments? Comments are not compulsory since they have no effects on your codes but highly recommended based on the above reasons. JavaScript have two(2) ways of writing comments: Single Line Comments We make use of the single line way of commenting when the comment won't span more than just a single line of text in the JavaScript source code (No line break involve). This means that, after the start of a single line comment, all texts or codes existing on the line where and after it was started won't be executed. Syntax We start a single line comment by simply writing two forward slashes (//) and then, the line of comment. EXAMPLE
//alert(5); this will not be executed

alert(5); //alert(5); this will not be executed


In most of our examples, we shall be making use of single line comments in explaining such examples. Multiple Line Comments Multiple line comments are the opposite of single line comments. This means, they span more than one line of codes and even to the end of the source codes if not closed. Syntax They are started with a forward slash and an asterisk (/*). They are also ended with an asterisk and a forward slash (*/). EXAMPLE
/*None of these codes will be executed.
This is because a multi line is in play

var i = 5;


We need to close the comment or it will continue to the end of the codes


/*Comment started

alert("Hello World");

End comment



  1. JavaScript comments allow us to define codes or write texts that should not be executed when a program is executing.
  2. This helps us in writing comments regarding what is being done in a program.
  3. JavaScript comments can either be single line or multiple line comments.
  4. Single line comments' effects are only on the line they were started and after they have been started.
  5. Single line comments are started with two forward slashes (//).
  6. Multiple line comments span multiple lines and can even affect all the codes in our script if not ended.
  7. Multiple line comments are started with a forward slash and then an asterisk (/*). They are ended with an asterisk and a forward slash (*/).
Take a short quiz on JavaScript Comments.
Ask a question or tell us if JavaScript Comments is easy or not.

Join our 1,090 subscribers to receive tutorials' updates!

  We won't spam your mail box. We hate it.

StackBeginner 2021 © Joseph Omamode