Open In App

How to write an Alert Box in JavaScript ?

Last Updated : 15 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

In JavaScript, you can use the alert() function to display an alert box with a message to the user. The alert box typically contains a message and an OK button, allowing the user to acknowledge the message.

Syntax:

alert("message");

Example: Here, the alert() function is called with the message "Hello, world!". When executed in a browser environment, this code will display an alert box with the message “Hello, world!” to the user. The user can then click the OK button to dismiss the alert box.

Javascript




alert("Hello, world!");



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads