zoukankan      html  css  js  c++  java
  • xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

    js & void & undefined & null

    The void operator evaluates the given expression and then returns undefined.

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void

    
    void function test() {
      console.log('boo!');
      // "boo!"
      return "undefined  === void 0 && null == void 0";
    }();
    
    try {
      test();
    } catch (e) {
      console.log(e);
      // ReferenceError: test is not defined
    }
    
    /*
    
    "boo!"
    
    ReferenceError: test is not defined
    
    */
    
    
    void 2 == '2';
    // false
    
    void (2 == '2');
    // undefined
    
    

    void

    
    void 0;
    // undefined
    
    undefined === void 0;
    // true
    
    null === void 0;
    // false
    
    null == void 0;
    // true
    
    
    undefined == null;
    // true
    
    // undefined == false;
    false
    
    null == false;
    // false
    
    
    const log = console.log;
    
    let varVoid = void 0;
    
    log(`var void =`, varVoid);
    // var void = undefined
    
    
    
    
    

    undefined

    const log = console.log;
    
    let varDefault;
    
    log(`var default =`, varDefault);
    // var default = undefined
    
    

    null

    const log = console.log;
    
    let vaNull = null;
    
    log(`var null =`,  vaNull);
    // var null = null
    
    

    html

    <body>
      <header>
        <h1>void(js expression)</h1>
      </header>
      <main>
        <article>
          <section>
            <div>
              <a href="javascript:void(0);">
                Click here to do nothing
                <span>javascript:void(0);</span>
              </a>
            </div>
            <div>
              <a href="javascript:void(1);">
                Click here to do nothing
                <span>javascript:void(1);</span>
              </a>
            </div>
            <div>
              <a href="javascript:void(true);">
                Click here to do nothing
                <span>javascript:void(true);</span>
              </a>
            </div>
            <div>
              <a href="javascript:void(document.body.style.backgroundColor='green');">
                Click here for green background
              </a>
            </div>
            <div>
              <a href="javascript:void(document.body.style.backgroundColor='white');">
                Click here for init background
              </a>
            </div>
          </section>
        </article>
      </main>
      <footer>
        <p>copyright&copy; xgqfrms 2020</p>
      </footer>
      <!-- js -->
      <script>
        const log = console.log;
      </script>
    </body>
    

    https://codepen.io/xgqfrms/pen/poyYGZw

    refs

    TypeScript



    ©xgqfrms 2012-2020

    www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


  • 相关阅读:
    smith waterman算法
    深度复数网络 Deep Complex Networks
    生成对抗网络 Generative Adversarial Networks
    dl +rec
    python 后台运行命令
    conversion vs recommendation
    激活pycharm
    keras 自定义 custom 函数
    keras 保存训练的最佳模型
    python memory-management
  • 原文地址:https://www.cnblogs.com/xgqfrms/p/13738750.html
Copyright © 2011-2022 走看看