Alert Function in JavaScript

JavaScriptThe very first JavaScript application which we are going to create, is Hello World.  For this, we need a very simple HTML code.  We are going to add our JavaScript code inside body tag.  However, we usually place it inside head tag.

JavaScript code is always placed inside script tag, which will have a type attribute.  Its value always will be “text/javascript” because it will let the browser engine know that this part contains JavaScript code.

In this JavaScript application, we are going to make use of alert function to display a message box containing text Hello World.  Alert function takes a string as parameter.  You can use this function to display an important message to your website users.

Sample code is given below.  Simply copy and paste it in Notepad++ and save it as html file.  Open that file in any browser like Google Chrome, Firefox etc and you will see a message box with text Hello World.

<!DOCTYPE html>
<html>
<head>
<title>JavaScript Tutorial </title>
</head>
<body>
<script type="text/javascript">
alert("Hello World");

</script>

</body>
</html>