Writing your first Hello, World! 🌍 JavaScript code Tutorial

Writing your first JavaScript "Hello World!" 🌍 program is simple as compared to other programming languages as you do not need any special software or IDE. To get started a simple text editor like Windows Notepad, or TextEdit if you work on a macOS is good enough! Also, to test your code your default browsers like Microsoft Edge or Safari will do! So let us see how our first JavaScript Hello World program looks like,

File: HelloWorld.html

<!DOCTYPE html>
<html lang="en">
<title>JavaScript : Hello World! Example</title>
<script>alert("Hello World!");</script>
<p>This is my first JavaScript Program saying hello in a alert message!</p>

Above what you see is a minimal HTML5 webpage template with a <script> tag in the head section, anything that you write inside it is the JavaScript code. alert() is a JavaScript method that when executed will display a prompt window as shown in the below image with the string message you pass in it.

JavaScript Hello World! Alert Message
JavaScript Hello World! Alert Message

How to run your first "Hello World!" JavaScript Code?

  1. Open a text editor: You should have Notepad if working on Windows or TextEdit if working on a Mac.
  2. Simply copy the above code content to the editor and save as "HelloWorld.html"
  3. Just double click the file and it should open up in your default web browser!
  4. If you see "Hello World!" alert pop-up! Your code worked! 😊, if not maybe something went wrong ❗️ Just recheck if you didn't do any of the above steps correctly.
  5. Click OK to close the alert box, see how you refresh your page the message is displayed again as each time you request the webpage JavaScript gets executed again.

Thats it! I hope this was helpful!

Try Out Code2care Dev Tools:


Android Java Linux Microsoft Google Python macOS Notepad++ Microsoft Teams CSS PHP SharePoint Html Linux C Programs Bootstrap jQuery Sublime Android Studio Facebook Eclipse WhatsApp News MySQL Json HowTos JavaScript FTP S3


Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Tutorials, Trouble-Shooting steps, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.
πŸŽ‰ We are celebrating the 10th years of Code2care! Thank you for all your support! We hope we made a difference.
We strong support Gender Equality & Diversity.

We stand in solidarity with Ukraine - Make a donation to UNHCR - https://donate.unhcr.org/in/en-in/ukraine-emergency