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 browser's 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 aleart 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!
- Add Animated Scrolling to Html Page Title Script
- How to get query string in JavaScript HTML location.search
- How to get current URL Location using Javascript HTML
- How to detect Browser and Operating System Name and Version using JavaScript
- Submit html form on dropdown menu value selection or change using javascript
- How to Print from JavaScript HTML using window.print
- JavaScript : Get url protocol HTTP, HTTPS, FILE or FTP
- JavaScript : Get current page address
- How to send email from JavaScript HTML using mailto
- Send Extra Data with Ajax Get or Post Request
- Write javaScript code in Swedish using FikaScript
- Get Device Screen Width and Height using javaScript
- How to get UTC (GMT) using javascript
- Javascript convert text case from uppercase to lowercase
- Loading previous page using html button using JavaScript
- [javaScript] Convert text case to lowercase
- Detect if Cookies are enabled using JavaScript
- Android Images with Rounded Corners : ImageView - Android
- Save webpage as pdf in Google Chrome for Mac OS X - Mac-OS-X
- Change SharePoint search results FullTextSqlQuery RowLimit 10000 - SharePoint
- SharePoint Excel error - The workbook cannot be opened because it contains the following features that are not supported by Excel in the browser - SharePoint
- FileZilla Connection time out Failed to retrieve directory listing - FTP
- Tutorial Java SOAP WebServices JAS-WS with Eclipse J2EE IDE and Tomcat Server Part 1 - Java
- Android RatingBar Example - Android
- How to use Content Assist in Eclipse IDE - Eclipse
- List of Java Keywords - Java
- [Solutions] Android Error in an XML file: aborting build. Eclipse SDK - Android
- How to configure PDF iFilter for SharePoint - SharePoint
- Create simple struts2 project using maven commands - Java
- Change Height of Android ActionBar - Android
- How to enable disable SharePoint Developer Dashboard for tracing troubleshooting - SharePoint
- Eclipse: Updating Maven Project. Unsupported IClasspathEntry kind=4 - Eclipse