Signup/Sign In
LAST UPDATED: DECEMBER 27, 2022

JavaScript Program to Write Hello World

JavaScript is a popular programming language that is widely used to create interactive elements on websites. It is a powerful language that allows developers to create complex and dynamic web applications.

In this tutorial, we will learn how to write a simple JavaScript program that prints the words "Hello World" to the console. This program is often used as a starting point for learning JavaScript, as it provides a simple example of how to use the language to write basic programs.

Method 1: Using console.log

This method is used to print any kind of variable or statement according to the user.

// Write a Hello World Program in JavaScript.

console.log("Hello World!");


Hello World!

Method 2: Using document.write

The write() the method writes directly to an open HTML Document stream on the user screen

// Write a Hello World Program in JavaScript.

document.write("Hello World!");


Hello World!

Method 3: Using alert

The alert() the method displays an alert box with a message and an OK button and is used mostly when we want an answer from the user.

// Write a Hello World Program in JavaScript.

alert("Hello World!");



Hello World!

How does a JavaScript Program execute?

JavaScript is a synchronous and single-threaded language.

Everything in JavaScript is wrapped inside a cluster known as Execution Context, which is basically an abstract concept and can be seen as a container of the stack which holds the whole information about the cluster within which the whole program/code is in execution.

Execution Context has two phases :

  • Memory Allocation Phase
  • Code Execution Phase

Take the first step towards becoming a JavaScript pro by signing up for our Interactive Course now!



About the author:
Proficient in the creation of websites. Expertise in Java script and C#. Discussing the latest developments in these areas and providing tutorials on how to use them.