JavaScript alert()

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.

The alert dialog box takes the focus and forces the user to read the specified message. So, we should avoid overusing this method because it stops the user from accessing the other parts of the webpage until the box is closed.

Syntax

alert(message)

Values

message: It is an optional string that specifies the text to display in the alert box. It consists of the information that we want to show to the users.

<!DOCTYPE html>
<html>
<head>
  <title>JavaScript</title>
  <script>
	var a = 40;
	var b = 20;
	
	if(a > b){
		alert(b + a);
	}else{
		alert("Value of B : " + b);
	}
  </script>
</head>
<body>
</body>
</html>