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.
// 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.
// 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.