alert()
The alert() method displays an alert box with a message and an OK button. The alert() method is used when we want to inform user regarding anything. The alert box takes the focus away from the current window, and forces the user to read the message first.
Syntax-
alert(message)
alert("Hello! This is an alert")
Output-
confirm()
The confirm() method displays a dialog box with a message, an OK button, and a Cancel button. The confirm() method returns true if the user clicked "OK", otherwise false.
A confirm box is often used if you want the user to verify or accept something. It also prevents the user from accessing other parts of the page until the box is closed.
Syntax-
confirm(message)
confirm("Do you still want to delete?");
Output-
prompt()
The prompt() method displays a dialog box with a message that prompts the user for input. The prompt() method returns the input value if the user clicks "OK", otherwise it returns null or default value if given. User may also click on cancel, then nothing will be returned.
A prompt box is used if we want the user to input a value. When a prompt box pops up, the user will have to click either "OK" or "Cancel" to proceed. It prevents the user from accessing other parts of the page until the box is closed.
Syntax-
prompt(text, defaultText)
prompt("Enter your name?", "guest");
Output-
If I enter the name "Rohit", then,
I hope you find this post helpful!