DEV Community

Cover image for Hello, World!
Osika Martha
Osika Martha

Posted on

Hello, World!

The well-known program "Hello World" is frequently used as a jumping-off point for learning a new programming language. In this article, we'll look at how to write a JavaScript "Hello World" program.

Building online apps frequently makes use of the high-level, interpreted programming language known as JavaScript. It is renowned for its adaptability, simplicity of usage, and ability to run on both the client and server sides.
A text editor and a web browser are required to write a JavaScript "Hello World" program. The steps are as follows:

Step one: Make a new HTML file.
Create a new file in your text editor after opening it. Using a ".html" extension, save it. This is the HTML file we'll use.

Step two: Add the JavaScript code.
Add the following code to the HTML file after opening it in your text editor:

<!DOCTYPE html>
<html>
<head>
    <title>Hello World in JavaScript</title>
</head>
<body>
    <script>
        // JavaScript code goes here
        console.log("Hello World!");
    </script>
</body>
</html>

Enter fullscreen mode Exit fullscreen mode

We've inserted a script tag with our JavaScript code to this code. The text "Hello World!" is printed to the browser console using the console.log() method.

Step 3: Launch a web browser and open the HTML file.
Open the file in a web browser after saving it. The "Hello World!" message ought to appear in the browser console.

Congratulations! You have successfully written a JavaScript "Hello World" program.

It is important to note that there are numerous approaches to writing a JavaScript "Hello World" program. For instance, you might use the alert() method to display the message in a pop-up window or the innerHTML property to add the message straight to the HTML file.

To sum up, JavaScript is an effective and flexible programming language that can be used to create a variety of web apps. You will be well on your way to becoming a skilled web developer by grasping the fundamentals of JavaScript, including how to write a "Hello World" program.

Top comments (0)