LOGBOOK

HELP

Quiz Entry - updated: 2026.07.14

What are the three built-in dialog box functions in JavaScript?

alert, confirm, and prompt pop up simple browser dialogs — to show a message, ask a yes/no question, or collect a line of text.

These are the quickest way to interact with a user, with no HTML needed. Each shows a small pop-up and returns a different kind of value:

Function Purpose Returns
alert(text) Show a message with an OK button undefined
confirm(text) Ask a Yes/No (OK/Cancel) question true or false
prompt(text, default) Ask for a line of text the user's input, or null if cancelled
alert('Hello!');                       // just shows a message

if (confirm('Are you 18 years old?')) {  // returns true/false
    alert('Welcome');
}

let name = prompt('What is your name?', 'Guest');  // returns a string
alert('Hello ' + name);

The key gotcha: these dialogs are blocking — they freeze the entire page until the user dismisses them, and you can't style them. That's fine for learning and quick experiments, but real applications almost always use custom modal dialogs built in HTML/CSS instead.

From Quiz: WEBT / Introduction to JavaScript | Updated: Jul 14, 2026