Hello World Program in Javascript

In this example, you will learn how to print a simple ‘Hello World’ program in javascript.

I m gonna practically explain to you how you can print “Hello, World!” using 3 different ways.

List of the Ways to Print Hello World




1. Using console.log()

console is the window object that has this method log() which helps to print logs on the console. console.log() is generally used for debugging purposes in javascript.

Source Code

console.log(“Hello World!”);


Hello World!

It prints the Hello World to the console.

2. Using alert()

alert() is the window object method. It is used to display an alert box with an OK button.

Source Code

alert(“Hello World!”);


Hello World!

It displays an alert with the message Hello World!

3. Using document.write()

document.write() is a DOM method that directly writes inside HTML.

Source Code

<!DOCTYPE html>


<p>Here is the output :</p>

document.write("Hello World!");

<p>You successfully printed your output</p>



It displays string output Hello World! inside HTML.

Leave a Comment

Your email address will not be published. Required fields are marked *