How to Create an Alert Box in JavaScript

Alert boxes are useful for displaying quick informational messages or warnings. They are displayed using JavaScript's alert function.

Things You'll Need

  • JavaScript or text editor
Show More

Instructions

  1. Create an Alert Box in JavaScript

    • 1

      Write the call to the alert function following the example:
      alert("Hello, World!");

    • 2

      Display the value of a variable or expression by passing it as the argument to the alert function:
      alert (my_variable);

    • 3

      Concatenate strings using the "+" operator to display multiple pieces of information in the alert box, as follows:
      alert ("You are " + age + " years old.");

Tips & Warnings

  • The confirm JavaScript function closely resembles alert, but gives the user two choices, OK and Cancel, instead of just OK.

Related Searches:

Comments

You May Also Like

Related Ads

Featured