JavaScirpt Tutorial Index

JavaScript Tutorial Javascript Example Javascript comment Javascript Variable Javascript Data Types Javascript Operators Javascript If Else Javascript Switch Statement Javascript loop JavaScript Function Javascript Object JavaScript Arrays Javascript String Javascript Date Javascript Math Javascript Number Javascript Dialog Box Javascript Window Object Javascript Document Object Javascript Event Javascript Cookies Javascript getElementByID Javascript Forms Validation Javascript Email Validation Javascript Password Validation Javascript Re-Password Validation Javascript Page Redirect Javascript Print How to Print a Page Using JavaScript Textbox events in JavaScript How to find the largest number contained in a JavaScript Array?

Misc

JavaScript P5.js JavaScript Minify JavaScript redirect URL with parameters Javascript Redirect Button JavaScript Ternary Operator JavaScript radio button checked value JavaScript moment date difference Javascript input maxlength JavaScript focus on input Javascript Find Object In Array JavaScript dropdown onchange JavaScript Console log Multiple variables JavaScript Time Picker Demo JavaScript Image resize before upload Functional Programming in JavaScript JavaScript SetTimeout() JavaScript SetInterval() Callback and Callback Hell in JavaScript Array to String in JavaScript Synchronous and Asynchronous in JavaScript Compare two Arrays in JavaScript Encapsulation in JavaScript File Type Validation while Uploading Using JavaScript or jquery Convert ASCII Code to Character in JavaScript Count Character in string in JavaScript Get First Element of Array in JavaScript How to convert array to set in JavaScript How to get current date and time in JavaScript How to Remove Special Characters from a String in JavaScript Number Validation in JavaScript Remove Substring from String in JavaScript

Interview Questions

JavaScript Interview Questions JavaScript Beautifier Practice Javascript Online Object in JavaScript JavaScript Count HTML Interpreter Getters and Setters in JavaScript Throw New Error in JavaScript XOR in JavaScript Callbacks and Promises in JavaScript Atob in JavaScript Binary in JavaScript Palindrome Number in JavaScript How to Get First Character Of A String In JavaScript How to Get Image Data in JavaScript How to get URL in JavaScript JavaScript GroupBy Methods difference-between-var-let-and-const-keyword-in-java-script JavaScript Beautifier Iterating over Objects in Javascript Find the XOR of two numbers without using the XOR operator

Javascript comment

JavaScript comments are used to explain JavaScript code. It is used to add information about the code, warnings or suggestions so that end users easily understand the code.

Types of JavaScript comments

Two types of JavaScript comments:
  1. Single-line Comment
  2. Multi-line Comment

Single-line Comment

Single-line comment is represented by double forward slashes (//). Any text between double forward slashes (//) and end of line will be ignored while program is executed. eg. Comment added before the statement.
<!DOCTYPE html>  
<html>  
<body>  
<script>  
// single-line comment //  
document.write("hello world");  
</script>  
</body>  
</html>
eg. Comment added after the statement.
<!DOCTYPE html>  
<html>  
<body>  
<script>  
var a=10;  
var b=20;  
var c=a+b; //It add values of a and b variable  
document.write(c); // print sum of 10 and 20  
</script>  
</body>  
</html>
Output
30

Multi-line comment

Multi-line comments can be used for single as well as multi-line comments. Multi-line comments start with /* and end with */. The text between them will be ignored by JavaScript. /* Write comment here */ Example
<!DOCTYPE html>  
<html>  
<body>  
<script>  
/* It is multi-line comment.  
It will not be displayed */  
document.write ("Example of JavaScript multi line comment");  
</script>  
</body>  
</html>