Posted in All Posts, Semester 2

JavaScript Basics – Dialog Boxes

There are three types of dialog boxes in JS.

  • Alert
  • Prompt
  • Confirm

Alert Box

It is used to display an alert with user’s desired message.
Syntax- alert("your message");
See the example below.

Try It Yourself

Prompt Box

It is used to take an input from the client.
Input via prompt function is always taken to be string.
To convert it to number, you have to use in-built js functions like parseInt(), Number() etc.
Syntax- prompt("message to user about what to input");
Below is an example.

Try It Yourself

Confirm Box

It is used to accept a true/false (1 or 0) value from the user.
Syntax- confirm("Do you want to exit?");
Below is an example to show how confirm() works.

Try It Yourself

We hope that you found this article to be helpful.
Please share your thoughts in the Comments Section.

If you liked this article, then please like our Facebook page.

Suggested Reading

Comment your thoughts

This site uses Akismet to reduce spam. Learn how your comment data is processed.