Learn JavaScript: Printing Your First Message
Tags: javascript, programming, tutorial, webdev
Published: 2023-04-18 08:51:30

## 🧩 The full series is hosted on [FahimFBA/JavaScript](https://github.com/FahimFBA/JavaScript). Make sure to check the repo.

If you're new to programming, the first program you'll probably write is the "Hello, World!" program. In this article, you'll learn how to write your first JavaScript program that prints the message "Hello, World!" to the console.

## ⚡ Step 1: Set Up Your Environment

Before you can write your first JavaScript program, you need to set up your environment. You can use any text editor to write your code, but I recommend using an integrated development environment (IDE) like Visual Studio Code (although it is a text editor, we can make it powerful like and IDE by installing necessary extensions), which has built-in support for JavaScript.

## ⚡ Step 2: Write Your Code

Open your text editor or IDE and create a new file called "hello-world.js". In this file, type the following code:

```javascript
console.log("Hello, World!");
```

This code uses the `console.log()` method to print the message "Hello, World!" to the console.

## ⚡ Step 3: Run Your Code

Now that you've written your code, you need to run it. You can run your JavaScript code in several ways:  

- Run it in a browser console: Open your web browser, press (**Ctrl** + **Shift** + **I**) to open the developer tools, navigate to the console tab, and paste your code into the console. Alternatively, you can right click and go to **Inspect**. Then simply click on the **Console** tab. 

The shortcut key for opening developer tools varies depending on the web browser. In Google Chrome, for example, the shortcut key for opening the developer tools is usually "Ctrl + Shift + I" on Windows and Linux, or "Command + Option + I" on Mac. In Firefox, the shortcut key is usually "Ctrl + Shift + K" on Windows and Linux, or "Command + Option + K" on Mac.
![Inspect](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fc8s596uf2b9soqm95xd.png)
- Use a JavaScript console: Open a command prompt or terminal window, navigate to the directory where your "hello-world.js" file is located, and run the command `node hello-world.js`.

- Use an online JavaScript console: You can also use an online JavaScript console like [JSFiddle](https://jsfiddle.net/) or [CodePen](https://codepen.io/) to run your code.


![JSFiddle](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b1ftyxafepulxaoea98o.png)


![CodePen](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n9czb3s4t9jeu2ur41tg.png)

## ⚡ Step 4: Check Your Output

If everything worked correctly, you should see the message "Hello, World!" printed to the console.

Congratulations, you've written and run your first JavaScript program! 🎉

## 😄 Conclusion

In this article, you learned how to write a simple JavaScript program that prints the message "Hello, World!" to the console. While this program may seem simple, it's an essential first step in learning JavaScript and programming in general. Keep practicing and building on this foundation, and you'll soon be able to write more complex programs. Good luck!

## 🧑‍💻 Follow me!

If you are interested in learning many programming related topics in depth and if you also prefer the video content, then you can check my [YouTube channel](https://www.youtube.com/@FahimAmin?sub_confirmation=1).

Also, you can follow me on:

GitHub: [FahimFBA](https://github.com/FahimFBA)
LinkedIn: [fahimfba](https://www.linkedin.com/in/fahimfba/)
Twitter: [Fahim_FBA](https://twitter.com/Fahim_FBA)
Website: [https://fahimbinamin.com/](https://fahimbinamin.com/)

If you want to support me, then [you can also buy me a coffee](https://www.buymeacoffee.com/fahimbinamin)!

Cover: Photo by <a href="https://unsplash.com/@gamell?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Joan Gamell</a> on <a href="https://unsplash.com/s/photos/javascript?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a>