In this post, we will learn how to write hello world program in JavaScript.
We will be writing the hello world program using three different methods to print “Hello, World!”. Those three methods are as follows:-
- Using console.log()
- Using alert()
- Using document.write()
So, without further ado, let’s begin this tutorial.
JavaScript Hello World Program
// JavaScript Hello World Program console.log("Hello, World!");
Output
Hello, World!
The console.log() method writes a message to the console. The console is used for testing and debugging purposes.
JavaScript Hello World Program Using alert()
// JavaScript Hello World Program alert("Hello, World!");
Output
Hello, World!
Another way to display Hello, World! Message is by using the alert() method. This alert() method displays an alert box with a message, which we pass as an argument to it.
JavaScript Hello World Program Using Document
// JavaScript Hello World Program document.write("Hello, World!");
Output
Hello, World!
The write() method writes a string of text to a document. The document.write() method is a part of Document API.
Conclusion
I hope after going through this post, you understand how to write a hello world program in JavaScript.
If you have any doubt regarding the program, feel free to ask us in the comment section. We will be delighted to help you.