Single Line Comments

A single-line comment in JavaScript is denoted by two forward slashes (//),

Syntax:

// your comment here

Example 1: This example illustrates the single-line comment. 

Javascript
// A single line comment  
console.log("Hello Geeks!");    

Output
Hello Geeks!

Example 2: In this example, we will assign values to some variables and explain them with single-line comments.

Javascript
// Declaring a variable and assign value to it
let geek = 'Computer science portal';
console.log(geek)

// Perform operation of addition of two numbers
let sum = 5 + 8
console.log(sum)

Output
Computer science portal
13

JavaScript Comments

JavaScript comments help explain code, making it easier to understand. You can also use them to temporarily disable parts of your code. The JavaScript compiler ignores comments when running the code.

Similar Reads

1. Single Line Comments

A single-line comment in JavaScript is denoted by two forward slashes (//),...

2. Multi-line Comments

A multiline comment in JavaScript is a way to include comments that span multiple lines in the source code....

JavaScript Comments to Prevent Execution

We can use // or /*…*/ to change the JavaScript code execution using comments. JavaScript Comments are used to prevent code execution and are considered suitable for testing the code....

Contact Us