This presents a dialog containing the warning message and an OK button.
Note that the text that is presented in the dialog is unformatted text and you cannot use HTML in the dialog box.
The alert() dialog box is modal on most platforms. It also blocks the script from continuing except on some versions of Netscape Navigator on Unix platforms. This behavior may become more common as desktop operating systems become more Unix-like and the Netscape Navigator core source code is deployed on newer operating systems. It is possible that this behavior will be exhibited on Mac OS X.
This method is useful for debugging. You can use it much like you would have used a printf() in C language debugging. Using alert() can sometimes be useful as an observable effect of calling a function or event handler. If you don't see the alert box, it's likely the event didn't call your handler.
You may be able to accomplish some rudimentary formatting but realistically due to font differences on platforms the only meaningful formatting is to place newline characters (\n) into the text to introduce a line break and to insert leading spaces for indentation.
This method does not return any meaningful value and if it is used in an assignment, the value undefined will be used.
Be aware that the dialog may be modal but that the script may or may not continue while the alert() dialog is displayed. It depends on the platform. On Windows, the script execution pauses until the OK button is clicked. On UNIX, the alert is displayed by a different process or thread and the script execution continues. If you need truly modal behavior you should consider the confirm() or prompt() dialogs instead.