JavaScript alert()/window.alert() | Alert Dialog Box

The JavaScript alert() method is used to display an alert dialog with an optional message. For example:

HTML with JavaScript Code
<!DOCTYPE html>

   <h2>The alert() Method</h2>
   <button onclick="myFunction()">Click Me to Alert</button>
      function myFunction() {
         alert("Hi there!");

The alert() Method

Note - The alert() is same as window.alert(). It is because, window is a global object. And in JavaScript, a method by default belongs to the window object.

JavaScript alert() Syntax

The syntax of alert() method in JavaScript, is:


The message is optional, used to display some information to the user, regarding the alert box.

JavaScript Online Test

« Previous Tutorial Next Tutorial »

Follow/Like Us on Facebook

Subscribe Us on YouTube