Labs ICT
โญ Pro Login

Comments

JavaScript Comments

Comments are notes you leave in your code for yourself and other developers. The computer ignores them completely, but humans rely on them to understand intent, logic, and context.

JavaScript supports three kinds of comments: single-line, multi-line, and JSDoc documentation comments.

Single-Line Comment

// This is a single-line comment
console.log("Hello");
Try it Yourself โ†’

Single-Line After Code

console.log("Hi"); // Inline comment
Try it Yourself โ†’

Multi-Line Comment

/*
  This is a multi-line comment.
  It spans multiple lines.
*/
console.log("World");
Try it Yourself โ†’

Commenting Out Code

// console.log("This won't run");
console.log("This will run");
Try it Yourself โ†’

Multi-Line Commenting Out

/*
console.log("Skipped line 1");
console.log("Skipped line 2");
*/
console.log("Active line");
Try it Yourself โ†’

JSDoc Comment

/**
 * Adds two numbers together.
 * @param {number} a - First number
 * @param {number} b - Second number
 * @returns {number} The sum
 */
function add(a, b) {
  return a + b;
}
Try it Yourself โ†’

JSDoc with Object Params

/**
 * @param {Object} user - User information
 * @param {string} user.name - User's full name
 * @param {number} user.age - User's age
 */
function showUser({ name, age }) {
  console.log(name, age);
}
Try it Yourself โ†’

Comment-Driven Development

// TODO: Implement error handling
// FIXME: This doesn't handle edge cases
// HACK: Temporary workaround for API bug
console.log("Working on it...");
Try it Yourself โ†’

๐Ÿงช Quick Quiz

How do you write a single-line comment in JavaScript?