DEV Community

Cover image for How to use window.confirm()
Dhairya Shah
Dhairya Shah

Posted on

How to use window.confirm()

Hello everyone, I am back with a new article on how you can use window.confirm() Browser API in JavaScript.

window.confirm() let you to ask confirmation before performing a important action; for example: deleting something or posting something

Let's look it by an example:

  const warn = confirm('You are going to delete this post, are you sure?')
Enter fullscreen mode Exit fullscreen mode

This will show you a confirmation message.
window.confirm() example

Now, how you can check whether user has confirmed or not?

  const warn = confirm('You are going to delete this post, are you sure?')
if(warn){
    console.log('User has confirmed')
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)