In the previous tutorial, you learned how to install JavaScript on your computer. Now, let's write a simple JavaScript program.
The following program displays Hello, World!
on the screen.
console.log("Hello, World!");
Output
Hello World!
Note: A Hello World!
program includes the basic syntax of a programming language and helps beginners understand the structure before getting started. That's why it is a common practice to introduce a new language using a Hello World!
program.
It's okay if you don’t understand how the program works right now. We will learn about it in upcoming tutorials. For now, just write the exact program and run it.
Working of the Program
Congratulations on writing your first JavaScript program. Now, let's see how the above program works.
In JavaScript, anything inside console.log()
is displayed as output.
There are two things to note about console.log()
:
- Everything we want to display is included inside the parentheses
()
. - The text we want to print is placed within double quotes
" "
.
We can also use single quotes to print text in the console. For example,
console.log('Hello World!');
is the same as
console.log('Hello World!');
To be consistent, we will be using double quotes throughout the tutorials.
Next, we will be learning about JavaScript comments.