DEV Community

Cover image for Learn JavaScript: Printing Your First Message
Md. Fahim Bin Amin
Md. Fahim Bin Amin

Posted on • Updated on

Learn JavaScript: Printing Your First Message

🧩 The full series is hosted on 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:

console.log("Hello, World!");
Enter fullscreen mode Exit fullscreen mode

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

  • 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 or CodePen to run your code.

JSFiddle

CodePen

⚡ 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.

Also, you can follow me on:

GitHub: FahimFBA
LinkedIn: fahimfba
Twitter: Fahim_FBA
Website: https://fahimbinamin.com/

If you want to support me, then you can also buy me a coffee!

Cover: Photo by Joan Gamell on Unsplash

Top comments (3)

Collapse
 
ahvir profile image
Sheikh Tanvir Ahmed

Great one, Bhai. Thanks a lot!

Collapse
 
fahimfba profile image
Md. Fahim Bin Amin

You're most welcome! 😊

Collapse
 
walidulhasan profile image
Walidulhasan boniamin

Is it OK