因为你可以看到提示返回false,当你按ok console.log打印为true。我真的很困惑,那是怎么发生的?提示读取,他们没有相同的字母,为什么它返回false?和控制台返回true因为它们具有相同的类型?
答案 0 :(得分:2)
confirm
的返回值不是基于您传递给它的表达式。它基于用户点击的按钮。因此,虽然'y'==='n'
始终为false
,但如果单击“确定”按钮,则confirm
将返回true。
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."));