JavaScript Tutorial - Statements and Comments

  1. What Is JavaScript Statement?
  2. JavaScript Comments

In this tutorial, we will learn about statements and comments.

What Is JavaScript Statement?

A statement is an instruction given to the computer. It is how programming languages in general work, not just JavaScript, but all programming languages.

The semicolon ; at the end of the statement means this is the end of the statement. Whenever you write a statement in JavaScript, you end your statement off with a semicolon and whatever comes after this is a completely new statement.



  <p>JavaScript Tutorial</p>

    document.write("Test string.")
    alert( 'Hello, world!' );


document.write("Test string.")

The first statement writes the text Test string. in the webpage.

alert( 'Hello, world!' );

This statement pops up an alert message box showing Hello, world!

JavaScript Comments

Comments are like notes to yourself or other programmers in the programming languages. It is good practice to keep comments in your code.

statement; // this is a comment

You should always leave comments like shown in your code, because after some weeks you might forget what your code actually does and then, if you’ve left a comment, then it could help yourself remember. Also, if another programmer looks at your code, he might not understand exactly what you are doing without comments.

If you break down to a new line, whatever you write underneath here isn’t commented out anymore,

JavaScript Multi-Line Comment

If your comments are long, you want to break them down to multiple lines, then you need to leave a multi-line comment.

Anything in between is
commented out.
Write for us
DelftStack articles are written by software geeks like you. If you also would like to contribute to DelftStack by writing paid articles, you can check the write for us page.

Related Article - JavaScript Statement