Questions And Answers

More Tutorials

Javascript window.alert()

The alert method displays a visual alert box on screen. The alert method parameter is displayed to the user in plain text:


Because window is the global object, you can call also use the following shorthand:


let's take the following example:

alert('hello, world');


Javscript alert example

The alert method is technically a property of window object, but since all window properties are
automatically global variables, we can use alert as a global variable instead of as a property of window -
meaning you can directly use alert() instead of window.alert().

Unlike using console.log, alert acts as a modal prompt meaning that the code calling alert will pause until the
prompt is answered. Traditionally this means that no other JavaScript code will execute until the alert is dismissed:

console.log('Alert was dismissed');

However the specification actually allows other event-triggered code to continue to execute even though a modaldialog is still being shown. In such implementations, it is possible for other code to run while the modal dialog is being shown.

More information about usage of the alert method can be found in the modals prompts topic.

The use of alerts is usually discouraged in favour of other methods that do not block users from interacting with the page - in order to create a better user experience. Nevertheless, it can be useful for debugging.


In this page (written and validated by ) you learned about Javascript window.alert() . What's Next? If you are interested in completing Javascript tutorial, your next topic will be learning about: Javascript window.prompt.

Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue:

Share On:

Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using, you agree to have read and accepted our terms of use, cookies and privacy policy.