JavaScript: alert()

The alert() method shows a short message in a dialog and pauses the current script until the user closes it.

What you will learn

Minimal example

alert("Please check the required fields.");
alert("First line\nSecond line");

The browser displays an OK button. JavaScript does not continue until the dialog is closed, so avoid showing alerts repeatedly or using them as the only way to explain a form error.

Common mistakes