What is alert() in javascript?

Posted by

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours scrolling social media and waste money on things we forget, but won’t spend 30 minutes a day earning certifications that can change our lives.
Master in DevOps, SRE, DevSecOps & MLOps by DevOps School!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

The alert() method in JavaScript is used to display a virtual alert box. It is mostly used to give a warning message to the users. It displays an alert dialog box that consists of some specified message (which is optional) and an OK button. When the dialog box pops up, we have to click “OK” to proceed.

suppose a user is required to fill the form in which some mandatory fields are required to enter some text, but the user forgets to provide the input. we can use the alert dialog box to show a warning message related to fill the textfield.

syntax

alert(message)  

example

<!DOCTYPE html>
<html>
<head>
		<title> alert in javascript</title>
</head>
<body>
		<script>
		var q=12;
		var r=23;
		if(q<r)
		{
		 alert("q is less then r");
		}
		else
		{
		  alert("q is greater than r");
		}
		</script>

</body>
</html>

output

guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x