JavaScript Tutorial - Statements and 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.
<!DOCTYPE HTML>
<html>
<body>
<p>JavaScript Tutorial</p>
<script>
document.write("Test string.")
alert( 'Hello, world!' );
</script>
</body>
</html>
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.
*/
Founder of DelftStack.com. Jinku has worked in the robotics and automotive industries for over 8 years. He sharpened his coding skills when he needed to do the automatic testing, data collection from remote servers and report creation from the endurance test. He is from an electrical/electronics engineering background but has expanded his interest to embedded electronics, embedded programming and front-/back-end programming.
LinkedIn Facebook