jQuery: 如果条件为假,但仍然执行?

jQuery: if condition is false, but still executed?

代码如下

  $(document).ready(function(){

    sessionStorage.test = false;  

    alert( sessionStorage.test );

    if ( sessionStorage.test ) {
      alert("I dont care about your conditions!");
    }

  });

生成以下弹出窗口:

false

I dont care about your conditions!

即使 sessionStorage.test 明确设置为 false。为什么会这样?根据这个答案 ,这应该可行。我究竟做错了什么?我正在使用 XAMPP - sessionStorage 是否有问题?这是我的测试文件的完整代码:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Test</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script >
      $(document).ready(function(){
        sessionStorage.test = false;    
        if ( sessionStorage.test ) {
          alert("I dont care about your conditions!");
        }
      });
    </script>
  </head>
  <body>
    <!-- page content -->
  </body>
</html>

会话存储的默认 getter/setter 是:

sessionStorage.setItem('keyName', 'value');    
sessionStorage.getItem('keyName')

因此,例如:

sessionStorage.setItem('test',false);    
if (sessionStorage.getItem('test') != "false") {
   ..........
}

重复主题:
- sessionStorage setItem returns true or false
- sessionStorage isn't working as expected