JavaScript Hello World Example: A Beginner's Guide

Bobby Jul 13, 2026

Welcome, aspiring JavaScript developers! If you're new to the world of JavaScript, you've probably heard about the classic "Hello, World!" example. This simple program is the traditional starting point for any programming language, and JavaScript is no exception. Let's dive into creating your first JavaScript program – a "Hello, World!" example – and explore some of its key features along the way.

the word hello - world written in neon green and pink on a black background with arrows
the word hello - world written in neon green and pink on a black background with arrows

The primary goal of the "Hello, World!" program is to display the words "Hello, World!" on the screen. In JavaScript, you can achieve this using the `console.log()` function. This function sends a message to the web browser's console, which can be viewed in the browser's developer tools. Let's create and run our first JavaScript program together.

the words hello world in green on a black background
the words hello world in green on a black background

Setting Up Your JavaScript Environment

Before we begin, ensure you have a suitable JavaScript environment. You can use various tools like online code editors (e.g., Replit, JSFiddle), or your preferred Integrated Development Environment (IDE). For this guide, let's use a simple HTML file with a script tag to contain our JavaScript code.

Here’s How Hello World in 15 Programming/Scripting Languages Looks Like
Here’s How Hello World in 15 Programming/Scripting Languages Looks Like

Create a new HTML file (index.html) and add the following content:

```html Hello, World! - JavaScript Tutorial ```

Running Your JavaScript Code

the words hello world are written in green and red letters on a black background,
the words hello world are written in green and red letters on a black background,

To run your JavaScript code, open the index.html file in a web browser. The browser's developer tools can be accessed using the following keyboard shortcuts:

  • On Windows/Linux: Press Ctrl + Shift + I
  • On Mac: Press Cmd + Opt + I

This will open the developer tools, where you'll find the "Console" tab. Your JavaScript outputs will appear here.

C# Hello World Program Example - Tutlane
C# Hello World Program Example - Tutlane

Creating Your "Hello, World!" Program

Now that you're set up, let's add your first JavaScript code to the script tag in your HTML file:

```javascript ```

Refresh your browser, open the console, and you should see:

an info sheet with the words, how do you write hello world? and some type of text
an info sheet with the words, how do you write hello world? and some type of text
"Hello, World!"

Congratulations! You've just written and run your first JavaScript program.

C++ Hello world program explanation - Code for Java c
C++ Hello world program explanation - Code for Java c
Salutare, lume! eng. Hello, world! - in 12 limbaje de programare - GNU/Linux
Salutare, lume! eng. Hello, world! - in 12 limbaje de programare - GNU/Linux
What is CSS? - Learn web development | MDN
What is CSS? - Learn web development | MDN
some type of text that is in the language hello world with different types of words
some type of text that is in the language hello world with different types of words
C Hello World Program - BTech Geeks
C Hello World Program - BTech Geeks
Hello, World! Iconic Programming Phrase Art
Hello, World! Iconic Programming Phrase Art
Hello world
Hello world
Custom cursor with mix-blend-mode
Custom cursor with mix-blend-mode
the words print hello world are written in different colors and font on a black background
the words print hello world are written in different colors and font on a black background
Printing "Hello World"
Printing "Hello World"
Embrace the Tech Realm with 'Hello World!' Code Design - Exclusive on TeePublic
Embrace the Tech Realm with 'Hello World!' Code Design - Exclusive on TeePublic
Css gradient for text
Css gradient for text
C++ print hello world - First C++ Program Hello World - BTech Geeks
C++ print hello world - First C++ Program Hello World - BTech Geeks
Pirple.com: Sharpen your skills.
Pirple.com: Sharpen your skills.
Printing "Hello World"
Printing "Hello World"
Hello, World! - Why Python is the Most Beginner-Friendly Coding Language
Hello, World! - Why Python is the Most Beginner-Friendly Coding Language
Hello World in X86 NASM Assembly
Hello World in X86 NASM Assembly
hello world #unit
hello world #unit
Hello world in 5 different programming languages
Hello world in 5 different programming languages
💻 Все о карьере в IT – в тг (тык)
💻 Все о карьере в IT – в тг (тык)

Exploring Different Output Methods

Though `console.log()` is the most common method for outputting results in JavaScript, it's not the only way. Let's explore two more methods: `alert()` and modifying the HTML directly using the Document Object Model (DOM).

Using the `alert()` function

The `alert()` function displays a pop-up box with the specified message. To use it, simply replace the `console.log()` line in your JavaScript code with:

```javascript alert("Hello, World!"); ```

Upon refreshing your browser, an alert box with the message "Hello, World!" will appear.

Modifying the HTML using the DOM

To display "Hello, World!" directly on the webpage, you'll need to modify the HTML using the Document Object Model (DOM). First, add an

element to your HTML file:

```html

```

Then, update your JavaScript code to assign the "Hello, World!" message to the 'message' element:

```javascript document.getElementById("message").innerText = "Hello, World!"; ```

Refresh your browser, and you should now see "Hello, World!" displayed on the webpage itself.

Conclusion and Next Steps

In this article, we've successfully created and explored various aspects of your first JavaScript program. You should now have a solid understanding of how to set up a basic JavaScript environment, output results using `console.log()`, `alert()`, and the DOM, and create a simple "Hello, World!" example.

To further enhance your JavaScript skills, consider exploring variables, data types, and control structures (e.g., if-else statements, loops) next. With each new topic, apply what you've learned by creating more complex examples. Happy coding, and welcome to the world of JavaScript!