DEV Community

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

Posted on

1

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)

Cloudinary image

Video API: manage, encode, and optimize for any device, channel or network condition. Deliver branded video experiences in minutes and get deep engagement insights.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay