Code Highlights logo

Learn

HTML list items

Comments

Comments allow us to explain our code, provide context, and make notes about its functionality or purpose. They can also be used to temporarily disable certain parts of our code during testing or debugging.

There are two types of comments in JavaScript:

  1. Single-line comments: Single-line comments are denoted by double slashes (//) at the beginning of the line. Anything after the double slashes will be ignored by the JavaScript interpreter.

    Example:

    1// This is a single-line comment

    Single-line comments are perfect for adding quick explanations or clarifications to specific lines of code.

  2. Multi-line comments: Multi-line comments, also known as block comments, allow us to comment out multiple lines of code or write longer explanations. They are enclosed between /* and */.

    Example:

    1/* This is a multi-line comment
    2that spans multiple lines.
    3It can be used to explain
    4complex logic or algorithms. */

    Multi-line comments are useful when writing detailed explanations, documenting functions or classes, or temporarily disabling a block of code.


Instructions

1.

Add a single-line comment just above the existing console.log statement, explaining what it does.

1// Prints the message "Hello, World!" to the console
2.

Add a multi-line comment below the existing code, providing a brief description of JavaScript.

1/* JavaScript is a high-level, interpreted programming language that
2is widely used for creating interactive web pages and applications. */

Sign up to start coding

Already have an account?

Sign In

Course content