Last Updated : 11 Jul, 2025
The JavaScript Hello World program is a simple tradition used by programmers to learn the new syntax of a programming language. It involves displaying the text "Hello, World!" on the screen. This basic exercise helps you understand how to output text and run simple scripts in a new programming environment.
How to Write a Simple JavaScript Hello World Program 1. Using the Browser ConsoleOne of the easiest ways to run JavaScript code is by using the browser's built-in console. Modern web browsers like Google Chrome, Firefox, and Edge provide developer tools that allow you to execute JavaScript code directly within the browser.
Steps:F12
or Ctrl+Shift+I
(Windows/Linux) or Cmd+Opt+I
(Mac) to open the Developer Tools.
console.log("Hello, World!");
2. Using an HTML File
You can also run JavaScript in a web page by embedding it inside an HTML document. This is the most common way JavaScript is used on websites.
Steps:.html
extension (e.g., hello-world.html
).
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello World in JavaScript</title>
</head>
<body>
<script>
alert("Hello, World!");
</script>
</body>
</html>
3. Using an External JavaScript File
For larger applications, it’s a good practice to separate JavaScript code into external files. This helps with better organization and reusability.
Steps:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello World in JavaScript</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
script.js
console.log("Hello, World!");
Conclusion
The Hello World program in JavaScript is a simple yet essential way to learn the basic syntax and functionality of the language. By following the examples in this guide, you can easily start writing and running JavaScript code in your browser or by creating web pages with JavaScript embedded.
Javascript program to print Hello World
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4