JavaScript Hello World Program

Howdy readers, today you will learn how to write a program to print hello world using JavaScript  Programming language.

JavaScript Hello World Program

As we know, “Hello, World!” is one of the simplest programs used to understand the basic syntax and structure of any programming language.

We will use three different methods to write a hello world program. The methods are as follows:-

  1. Using console.log()
  2. Using alert()
  3. Using document.write()

So, without any delay, let’s begin this tutorial.

JavaScript Hello World Program Using Console.log()

JavaScript Program

// JavaScript Program to Print "Hello, World!" Using Console.log()
console.log("Hello, World!");

Output

Hello, World!
JavaScript Program to Print Hello World

Explanation

console.log("Hello, World!");

The console.log() method outputs a message to the console. 

JavaScript Program to Print Hello World Using alert()

JavaScript Program

// JavaScript Program to Print Hello World Using alert()
alert("Hello, World!");

Output

Hello, World!

Explanation

alert("Hello, World!");

The alert() method displays an alert box with a message and an OK button. The alert() method is used to display a virtual alert box. It is mostly used to give a warning message to the users.

JavaScript Program to Print Hello World Using document.write()

JavaScript Program

// JavaScript Program to Print Hello World Using document.write()
document.write("Hello, World!");

Output

Hello, World!

Explanation

document.write("Hello, World!")

The document.write() is used to display a given text on a web page. This is mainly used for testing purposes. 

Conclusion

I hope after reading this post, you understand how to write a program to print hello world using JavaScript Programming language.

If you have any queries regarding the tutorial, then let us know in the comment section. We will be glad to solve all of your queries.

Leave a Comment