This JavaScript tutorial explains how to use feedback in the JavaScript language with syntax and examples.
Description
In JavaScript, you can place remarks in your code that are no longer accomplished as part of the code. These feedback can appear on a single line or span across more than one lines. Let’s explore how to remark your JavaScript code.
JavaScript helps the identical commenting patterns as the C and C++ languages.
Syntax
There are two syntaxes that you can use to create a comment in JavaScript.
Syntax Using // symbol
The syntax for developing a remark in JavaScript the usage of // image is:
// comment goes here
A comment started with // symbol ought to be at the end of a line in your JavaScript code with a line spoil after it. This approach of commenting can solely span a single line within the JavaScript and need to be at the cease of the line.
Syntax Using /* and */ symbols
The syntax for creating a remark in JavaScript the usage of /* and */ symbols is:
/* comment goes here */
A remark that starts offevolved with /* symbol and ends with */ can be anywhere in the JavaScript code. This approach of commenting can span numerous traces within the JavaScript.
Example – Comment on a Single Line
Let’s look at an instance that suggests how to create a comment in JavaScript that is on a single line.
For example:
Here is a remark that seems on its own line in JavaScript:
/* Author: TechOnTheNet.com */
var h = 100;
Here is a comment that appears at the end of the line in JavaScript:
var h = 100; /* Author: TechOnTheNet.com */
or
var h = 100; // Author: TechOnTheNet.com
Example – Comment on Multiple Lines
You can also create a comment that spans a couple of traces in your JavaScript code.
For example:
/*
Author: TechOnTheNet.com
Purpose: To show a comment that spans multiple lines in JavaScript
*/
var h = 100;
This comment spans throughout multiple traces in JavaScript and in this example, it spans across 4 lines.
JavaScript will assume that the whole thing after the /* image is a comment till it reaches the */ symbol, even if it spans multiple strains inside the JavaScript code.
Example – Comment to Prevent Execution of Code
You can also use remarks to prevent strains of JavaScript code from being executed.
For example:
// var h = 100;
tag = tag.toUpperCase();
This comment will prevent the variable h from being declared with a cost of a hundred in JavaScript.
You can also forestall multiple traces of JavaScript from being executed.
For example:
/*
var h = 100;
tag = tag.toUpperCase();
*/
By the use of the /* and */ symbols, we’ve avoided each lines of JavaScript code from being executed. In this example, both the assertion of the variable h will be averted as properly as the conversion of the variable known as tag to uppercase.
Leave a Review