Lecture

Comment

Comments are used by developers to explain the purpose, functionality, changes in the code, or to temporarily disable parts of the code.


Types of JavaScript Comments

JavaScript uses different comment symbols for single-line and multi-line comments.


Single-line Comment

A single-line comment begins with // and comments out the rest of the line.

Example of Comment Usage
// This is a single-line comment console.log('Hello, World!'); // This message will be printed to the console

Multi-line Comment

A multi-line comment starts with /* and ends with */. This style is used for comments that span multiple lines.

Multi-line Comment
/* This is a multi-line comment. The content within the comment is not executed. */ console.log('Hello, World!');

Usage of JavaScript Comments

  1. Code Explanation: Use comments to describe the function, operation principles, or purpose of variables or functions in the code.
Explaining Code with Comments
// Assign 10 to the variable x. let x = 10;

  1. Code Deactivation: Comments can be used to disable specific code parts temporarily for bug tracking, debugging, or other purposes.
Disabling Specific Code
// console.log("This won't run");

  1. Indicating TODO and FIXME: Adding comments to parts of the code that are under development or need modification allows you to easily find and fix them later. TODO is used to indicate tasks that need to be done, while FIXME highlights parts needing correction.
TODO Comment for Future Tasks
// TODO: Implement additional features here

Caution:

  • Although comments do not affect code execution, excessive commenting can reduce code readability. It is best to use comments appropriately where necessary.

  • Avoid including sensitive information or unnecessary personal details in comments.

Mission
0 / 1

What is the most appropriate word to fill in the blank?

In JavaScript, a single-line comment starts with .
/*
//
<!--
#

Lecture

AI Tutor

Design

Upload

Notes

Favorites

Help

Code Editor

Run

Execution Result