Skip to content

WebDevHubs

  • Home
  • HTML
  • CSS
  • JavaScript
  • Web Technologies
  • Web Templates
  • Toggle search form

JavaScript Program to Print Hello World | First JavaScript Code

Posted on March 13, 2025March 13, 2025 By Jyoti No Comments on JavaScript Program to Print Hello World | First JavaScript Code

The “Hello World” program is the simplest program you can write in any programming language. It serves as a first step for beginners to get familiar with the syntax and environment of a new programming language. In JavaScript, the goal of this program is to print “Hello World” on the screen or console.

There are various methods to print Hello World on the screen. These are –

  • Using console.log() Method
  • Using alert() Method
  • Using document.write() Method

1. Using console.log() Method

The console.log() method display output in the browser’s developer console. This is one of the most frequently used methods to print messages for debugging and development purposes.

// Print Hello World on browser console
console.log("Hello World");

In above example, the string "Hello World" is logged to the console.

2. Using alert() Method

The alert() method creates a pop-up dialog box displaying the message. This method is useful for alerting users to important information.

// Display Hello World in an alert box
alert("Hello World");

This will open a pop-up box in the browser with the message “Hello World”.

3. Using document.write() Method

The document.write() method writes directly to the web page. Although not commonly used in modern development (as it can overwrite the page content). It is useful for understanding how JavaScript can interact with the DOM.

// Write Hello World directly to the document
document.write("Hello World");

This method will display the text “Hello World” on the webpage itself, not in the console.

JavaScript, Web Technologies Tags:JavaScript-Basic-Program, JavaScript-Program

Post navigation

Previous Post: How to Compare Arrays in JavaScript?
Next Post: HTML Unordered Lists

Leave a Reply Cancel reply

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

Archives

  • June 2025
  • May 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024

Categories

  • CSS
  • HTML
  • JavaScript
  • Lodash
  • PHP
  • Python
  • Web Technologies
  • Web Templates

Recent Posts

  • JavaScript Array isArray() Method
  • JavaScript Array forEach() Method
  • JavaScript Array includes() Method
  • JavaScript Array keys() Method
  • JavaScript Array lastIndexOf() Method

Recent Comments

No comments to show.

Copyright © 2025 WebDevHubs.

Powered by PressBook Green WordPress theme