Cover Image for JavaScript alert()
112 views

JavaScript alert()

The alert() function is a built-in function in JavaScript that displays a simple dialog box with a message and an OK button. It is commonly used for displaying informational messages or alerts to the user.

Here’s an example of how to use the alert() function:

JavaScript
alert("Hello, world!");

When this code is executed, a dialog box will appear with the message “Hello, world!” and an OK button. The script execution will be paused until the user clicks the OK button.

The alert() function can also accept variables or expressions as arguments:

JavaScript
const name = "John";
alert("Hello, " + name + "!");

In this example, the value of the name variable is concatenated with the “Hello, ” and “!” strings to form the message that will be displayed in the dialog box.

Please note that the alert() function is a basic way to display messages to the user, but it can be disruptive and interrupt the user’s flow. Consider using more user-friendly alternatives like displaying messages within the web page or using browser-specific APIs for notifications.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS