The alert()
method in JavaScript is used to display a message to the user. This method takes a string argument that specifies the message to be displayed, and displays an alert dialog box with the specified message. The alert()
method blocks further execution of the script until the user dismisses the alert dialog box.
Here is an example of how the alert()
method works:
const string1 = 'Hello, world!';
alert(string1);
// this will display an alert dialog box with the text 'Hello, world!'
In the code example above, we first declare a string called string1
that contains the text Hello, world!
. We then use the alert()
method to display an alert dialog box with the string1
string as the message. We pass the string1
string as an argument to the alert()
method to specify the message to be displayed.
As a result of calling the alert()
method, an alert dialog box will be displayed with the text Hello, world!
. The execution of the script will be blocked until the user dismisses the alert dialog box.
Leave a Reply