The window.alert() method is used to display a message in a popup alert box. It temporarily halts the user interaction with the page until they acknowledge the message by clicking the “OK” button.

Example:

JavaScript
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Alert Box Example</title>
  <script>
    function showAlert() {
      alert("This is an alert box!");
    }
  </script>
</head>
<body>
  <button onclick="showAlert()">Show Alert</button>
</body>
</html>
  • Usage: Useful for displaying simple messages or warnings to the user.
  • Consideration: Overuse of alert boxes can disrupt the user experience. They should be used sparingly.