You might have experienced a message that pops up on the top of the screen that indicates some sort of message displaying to you. Wondered it, how you were displayed with the message? It’s Alert box in JavaScript.

It looks something like this.

alert box in javascript

In JavaScript Programming language it is very easy and possible to display alert box in our website.

Why do we use Alert box in JavaScript?

In JavaScript, Alert box is used to show a message to a user. For example a user intended to click on a link which he is not allowed to access so once the user will click on the link a message will be displayed to the user with context like “you are not allowed to click on the link”.

Alert boxes are one of most powerful built-in function in JavaScript. As we understood earlier in our series that JavaScript is however a client side language but we can even be usable in any back end programming language like PHP and python. So, we can clearly state how powerful is this programming language is. We can use these built-in functions like Alert box in PHP or python as well.

Syntax of Alert box is very simple. You just have to call the function and rest is completed and is fulfilled by JavaScript itself.

Alert box in JavaScript Syntax

alert()

This is as simple as it is shown above. Within the round brackets, you type your message and it is displayed on the page. Let’s complete it with a simple code. We’d prefer to use HTML as well to see a better result.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Alert box in JavaScript</title>
</head>
<body>
    <script>
        alert ("Welcome to JavaScript series")
    </script>
</body>
</html>

Output

Alert box in JavaScript

Here is an another example of alert boxes in JavaScript

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Alert box in JavaScript</title>
</head>
<body>
    <script>
        alert ("JavaScript is very intresting language")
    </script>
</body>
</html>

Output

alertboxes in JavaScript

Alert boxes in JavaScript displays the message when the page is loaded or any action is performed depending upon the programmer at what extent the programmer wants it to be executed. Thanks to ECMAscript and JavaScript programming language.

ALERT BOXES IN JAVASCRIPT

READ MORE FROM HERE

These topics might interest you

Leave a Reply

Your email address will not be published. Required fields are marked *