简体   繁体   中英

confirm() results return different results from console.log()

不同的结果

在此处输入图片说明

as you can see prompt returns false and when you press ok console.log prints true. I was really confused how did that happened? does prompt reads, they do not have the same letter reason why it returns false? and console returns true coz they have the same type?

The return value of a confirm is not based on your expression you pass into it. It is based on what button the user clicked. So, while 'y'==='n' will always be false , the confirm will return true if the OK, button is clicked.

 console.log(confirm("If you click OK, 'true' is returned. If you click Cancel, 'false' is returned. What's returned has nothing to do with the value you pass to the confirm() method. That is simply the data to be displayed in the dialog."));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM