Course
Comments
JavaScript Tutorial
This JavaScript tutorial is crafted for beginners to introduce them to the basics and advanced concepts of JavaScript. By the end of this guide, you'll reach a proficiency level that sets the stage for further growth. Aimed at empowering you to progress towards becoming a world-class software developer, this tutorial paves the way for a successful career in web development and beyond.
Comments
JavaScript Comments
In JavaScript, comments are used to add explanatory notes within the code. These comments are not executed by the browser and are purely for human understanding.
There are two ways to add comments in JavaScript:
- Single-line Comments: Single-line comments start with
//
and continue until the end of the line. They are useful for adding short explanations or notes.
<html><head> <title> Single line comments </title></head><body> <script> // Defining the string1 var string1 = "JavaScript"; // Defining the string2 var string2 = "TypeScript"; // Printing the strings document.write(string1, " ", string2); </script></body></html>
- Multi-line Comments: Multi-line comments begin with
/*
and end with*/
. They can span across multiple lines and are typically used for longer descriptions or commenting out blocks of code.
<html><head> <title> Multi line comments </title></head><body> <script> var a = 100; var b = 200;
/* a = a + b; b = a - b; a = a - b; */
document.write("a = " + a + "<br>" + "b = " + b); </script></body></html>