JavaScript Modals - Prompts Usage of alert()

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

The alert() method of the window object displays an alert box with a specified message and an OK or Cancel button. The text of that button depends on the browser and can't be modified.

Syntax

alert("Hello world!");
// Or, alternatively...
window.alert("Hello world!");

Produces

Image of alert

An alert box is often used if you want to make sure information comes through to the user.

Note: The alert box takes the focus away from the current window, and forces the browser to read the message. Do not overuse this method, as it prevents the user from accessing other parts of the page until the box is closed. Also it stops the further code execution, until user clicks OK. (in particular, the timers which were set with setInterval() or setTimeout() don't tick either). The alert box only works in browsers, and its design cannot be modified.

ParameterDescription
messageRequired. Specifies the text to display in the alert box, or an object converted into a string and displayed.

Return value

alert function doesn't return any value



Got any JavaScript Question?