Alert, confirm and prompt functions in Javascript.

One of the most interesting topics for beginners in Javascript is features. It is used for notification or confirmation of transactions.

In this article I will talk about the most frequently used functions in javascript: “alert”, “prompt”, “confirm”.

What is the alert function?

It is mainly used to show users a message, ie a kind of warning. For example:

alert (“Hello World!”);

And our output will be as follows:

What is the Prompt function?

The Prompt command is used to get input from a single user, ie the keyboard. And there are 2 ways to use it:

1)prompt(“Whats is your name?”);

And our output is:

2)prompt(‘What is your name?’, “Mack”);

And our output is:

As you can see, we were greeted by “Mack” which we wrote by default.

As you can see, we received input from the user with prompt. But before we get the input, we have to apply it to some variable so that the function we wrote about later doesn’t “fly away”.

  1. var variable = prompt(“How old are you?”);

2) var variable = prompt(“How old are you?” , ‘19’);

As you can see, our function is already stored in a variable, and we can call it again at any time.

What is the Confirm function?

As you know, some programs, websites, and even operating systems ask us for permission for some of the operations we see. For example, if you want to delete any file or image in Windows, you will be faced with a permission window like “Are you sure you want to delete this file?”.

In Javascript, this is done with the confirm function. The confirm function is used to get permission from the user. Consists of a two-button window (True / False). How to use: The Confirm function will return “true” if the user selects “Ok”, and “false” if “Cancel”:

var variable = confirm(“Do you wany delete this folder?”);

What are the disadvantages of Javascript functions?

  1. The browser function can display the output anywhere. Bi Firefox is in the middle of the screen in Mozilla, and at the top of the screen in Opera and Chrome.
  2. Increase the width of the window, give it color and shape, etc. It is impossible to do style work like.
  3. Before using the website, you must click ok, cancel or ESC in the window that opens to close the window.

Full-Stack developer. Founder of The-Black. Editor of Star Gazers publication. BEU