(dialog) Step 1 — choose OK or Cancel
Step 2 — runs after choice: true
(or false if Cancel)
How It Works
First line blocks. Dialog shows the question.
User chooses. Blocking ends with a boolean.
Next line runs. Console logs the follow-up text + result.
Production tip. Prefer non-blocking in-page modals for normal UI.
Compatibility
Browser Support
Window.confirm() is marked Baseline Widely available on MDN (since July 2015). Browser Window API — not a Node.js built-in.
✓ Baseline · Widely available
confirm()
Show an OK/Cancel dialog across modern browsers.
99%Core tag support
ChromeYes
Full support
EdgeYes
Full support
FirefoxYes
Full support
SafariYes
Full support
OperaYes
Full support
HTML element100% supported
Bottom line: Safe for learning and quick confirmations. Prefer custom UI for polished product flows.
Frequently Asked Questions
It shows a modal dialog with an optional message and OK/Cancel buttons, then returns true if the user confirms or false if they cancel or dismiss the dialog.
No. MDN marks Window.confirm() as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
A boolean: true for OK, false for Cancel (or dismiss). If the browser ignores in-page dialogs, MDN notes the return value is always false.
Both work in browsers. confirm is a method on the global window object, so confirm(message) and window.confirm(message) are the same.
No. Native confirm dialogs use the browser UI. For custom styling, use HTML (for example a <dialog>) with your own CSS and JavaScript.
Use alert() for a one-way message. Use confirm() when you need a yes/no decision before continuing—such as deleting data or leaving unsaved work.