JavaScript comments serve multiple purposes: clarifying JavaScript code to enhance readability and understanding, and also temporarily disabling code execution for testing alternative solutions.
Single-line comments in JavaScript start with //
, and any text following //
until the end of the line is ignored by JavaScript and not executed. The example below shows how to use single-line comments before each line of code.
Example
// Change heading: |
In this example, a single-line comment is placed at the end of each line to provide explanations for the code.
Example
let x = 5; // Declare x, give it the value of 5 |