JavaScript Hello World | Alert Function | Print example

When you start Learning any programming First need to write basic syntax of it. So Let’s start With a JavaScript Hello World first program.

JavaScript is a very powerful and popular language nowadays. It mainly used in a web application with HTML and CSS. And it’s also used for server-side programming using a nodejs. This tutorial you will learn How to write a Hello World in an HTML page using a JavaScript Function.

JavaScript Hello World | Alert Function | Print example

When using a browser, you can use a print out function and results called “console.log”.

How to start First Javascript Program

Before start JavaScript, you must know basic of HTML. Follow below this tutorial link:-

After that, you need to use a <head> tag. Inside head tag, you have to use a <script> tag. It’s not always required a <script> tag inside <head> tag.

Let’s see Javascript Hello World Examples

Here is 3 ways to print a “Hello world” in JavaScript programming language.

  • Print in HTML Tag
  • Use Alert box
  • Pring in Console

1. Print Javascript Hello world Function in HTML Tag

It’s a very easy, use a <p> tag with an id. Then write code in <script>. See below example of the Javascript print hello world.

Output: A launched in browser, you can see the output.

2. JavaScript Alert Hello World | Alert box

This is also easy just to use an alert() function with a message. An alert box used for giving acknowledgment to the user.

Output: A pop will come on the browser window with a message and close button.

JavaScript Alert Hello World Alert box output

3. JavaScript Hello World Console

Using the console.log()method, also print a string. This is important when you required to see the application log at the development phase.

Output: You have to open inception element -> console, to see the output in the browser.

JavaScript Hello World Console output

Hope you learn how to write the first JavaScript. Do comment if you have any doubt or suggestions.

Note: The JavaScript Hello World Examples are tested on Safari browser (Version 12.0.2).
OS: macOS 10.14 Mojave
Version: HECMAScript 2018


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.