GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Home
  • ES6
  • Web
  • JS BOM
  • JS DOM
  • Web API
  • React
  • Node.js
  • Express
  • React Native
  • JavaScript Array Methods
  • JavaScript String Methods
  • Regular Expressions
  • ES Next

This view

  • Original page
  • New address

GeezerVison is showing www.javascripttutorial.net — JavaScript alert()

Home » JavaScript BOM » JavaScript alert

Summary: in this tutorial, you will learn how to display an alert dialog by using the JavaScript alert() method.

Introduction to JavaScript alert() method #

The browser can invoke a system dialog to display information to the user.

JavaScript alert

The system dialog is unrelated to the webpage being shown in the browser. It also does not contain any HTML. Its appearance depends solely on the current operating system and browser, rather than CSS.

To invoke an alert system dialog, you invoke the alert() method of the window object.

window.alert(message);

Or

alert(message);

The message is a string that contains information that you want to show to users.

For example:

alert('Welcome to JavaScriptTutorial.net!');

When the alert() method is invoked, a system dialog shows the specified message to the user followed by a single OK button.

You use the alert dialog to inform users of something they have no control over, such as an error. After reading the message, users can only dismiss the dialog.

Note that the alert dialog is synchronous and modal. It means that the code execution stops when a dialog is displayed and resumes after it has been dismissed.

For example, the following code displays an alert dialog after three seconds:

setTimeout(() => {
    alert('3 seconds has been passed!')
}, 3000);

Summary #

  • The alert() is a method of the window object.
  • The alert() method is modal and synchronous.
  • Use the alert() method to display information that you want users to acknowledge.

Was this helpful?

Thank you for your feedback!

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.