An alert dialog box is mostly used to inform or alert the user by displaying some messages in a small dialogue box. Following is the syntax for it:
alert("YOUR MESSAGE COMES HERE");
Let's take an example to see it in action.
Also, based on what the user clicks on we can perform different actions. We can specify this course of action with conditional logic.
let result = window.confirm("SOME TEXT MESSAGE");
When the user clicks on the OK button then the result variable will get the value true and if the user clicks on the Cancel button the result variable will get the value false.
Let's take an example and see this in action:
let result = prompt("SOME MESSAGE", "DEFAULT_VALUE");
Here, SOME MESSAGE is the message which is displayed in the popup box, and DEFAULT_VALUE is the default value in the input field. The default value is an optional field.
The value returned by the prompt depends on what exactly the user does with the dialog.