JavaScript Message Boxes
JavaScript Message Boxes
confirm(), prompt()
JavaScript provides built-in global functions to display popup
message boxes for different purposes.
Note:
In JavaScript, global functions can be accessed using the window object
like window.alert(), window.confirm(), window.prompt().
alert()
The alert() function displays a message to the user to display some
information to users. This alert box will have the OK button to close
the alert box.
Syntax:
window.alert([message]);
Example: alert()
alert("This is an alert message box."); // display string message
Syntax:
bool window.confirm([message]);
Example: confirm()
var userPreference;
prompt()
Use the prompt() function to take the user's input to do further
actions. For example, use the prompt() function in the scenario where
you want to calculate EMI based on the user's preferred loan tenure.
Syntax:
string prompt([message], [defaultValue]);