Plenty of π
Module 2: Variables, Data Types, Type Casting, and Comments
Comments: Single-line and Multi-line

Comments are notes in your code that are ignored by the JavaScript engine. They are used to explain your code, make it more readable, or temporarily disable parts of it.

1. Single-line Comments: Start with //. Everything from // to the end of the line is a comment.

// This is a single-line comment.
let x = 10; // This comment explains the variable x.

2. Multi-line Comments: Start with /* and end with */. Everything between /* and */ is a comment, even across multiple lines.

/*
This is a
multi-line comment.
It can span several lines.
*/
let y = 20;

/* Another example: let z = 30; */

Why use comments?

  • Explain complex logic: Make it easier for others (and your future self) to understand what your code does.
  • Clarify intentions: Explain why you wrote the code a certain way.
  • Leave notes or TODOs: // TODO: Refactor this function later.
  • Temporarily disable code (commenting out): Useful for debugging.
    // console.log("This line is temporarily disabled.");
    

Good commenting practice makes code more maintainable and collaborative.