JavaScript confirm() Method instructs the browser to display a dialog and to wait until the user either confirms or cancels the dialog. You can set an optional message to display in the confirmation dialog.
confirm(message)
Note: This method returns true if the user clicked “OK”, otherwise false.
JavaScript confirm() Method example
Simple example code.
<!DOCTYPE html>
<html>
<head>
<body>
<button onclick="show()">Click me!</button>
<script>
function show() {
confirm("Press OK to close this option");
}
</script>
</body>
</html>
Output:

Another example with if statement.
<script>
if (confirm("Press a button!") == true) {
text = "You pressed OK!";
} else {
text = "You canceled!";
}
console.log(text)
</script>
Do comment if you have any doubts or suggestions on this JS method tutorial.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version

Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.