What is alert() in javascript?

Posted by

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