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">
<head>
<title>JavaScript : Hello World! Example</title>
<script>alert("Hello World!");</script>
</head>
<body>
<p>This is my first JavaScript Program saying hello in a alert message!</p>
</body>
</html>
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.
How to run your first "Hello World!" JavaScript Code?
- Open a text editor: You should have Notepad if working on Windows or TextEdit if working on a Mac.
- Simply copy the above code content to the editor and save as "HelloWorld.html"
- Just double click the file and it should open up in your default web browser!
- 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.
- 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!
- How to get UTC (GMT) time using JavaScript
- Submit html form on dropdown menu value selection or change using javascript
- How to detect Browser and Operating System Name and Version using JavaScript
- JavaScript : Get current page address
- [javaScript] Convert text case to lowercase
- How to check if a String contains substring or a word using javaScript
- Writing your first Hello, World! 🌍 JavaScript code Tutorial
- JavaScript: Check if variable is a number
- How to send email from JavaScript HTML using mailto
- Meaning of javascript:void(0) explained with example
- How to get query string in JavaScript HTML location.search
- Javascript convert text case from uppercase to lowercase
- Loading previous page using html button using JavaScript
- JavaScript : Get url protocol HTTP, HTTPS, FILE or FTP
- How to get current URL Location using Javascript HTML
- Detect if Cookies are enabled using JavaScript
- Write javaScript code in Swedish using FikaScript
- Add Animated Scrolling to Html Page Title Script
- JavaScript: Convert an Image into Base64 String
- Remove items from JavaScript array
- Send Extra Data with Ajax Get or Post Request
- How to Print from JavaScript HTML using window.print
- Get Device Screen Width and Height using javaScript
- Examples: Convert String to int in JavaScript
- npm WARN saveError ENOENT: no such file or directory, open /mnt/c/package.json
- How to copy Chrome alert popup text to clipboard - Chrome
- [Error] zsh: command not found: mvn - HowTos
- How to Disable Mac Terminal Bell Sound - MacOS
- Difference between using Scanner Class and String args for user input in Java - Java
- [Solution] The connection to the remote PC was lost, preparing to reconnect - Windows RDP - Windows
- How to Detect Phone Shakes Android Programming - Android
- Where are screenshots saved on Windows 11 using Snipping Tool? - Windows-11
- Java equals method - Tutorial - Java