Javascriptのvoid操作子

3228 ワード

  • 由来:原文
  • void 0とはどの値なのか、これは簡単にテストできます.
  • typeof void 0 //  "undefined"
    console.log(void 0) //  undefined
    
    void 0はundefinedのようですが、厳密ではないので、答えられません.void 100、void hello()、void i++という無数の組み合わせの値は何ですか?
  • ECMAScript 262では、以下のように説明されています.
  • The void Operator
    The production UnaryExpression : void UnaryExpression is evaluated as follows:
    Let expr be the result of evaluating UnaryExpression.
    Call GetValue(expr).
    Return undefined.
    NOTE: GetValue must be called even though its value is not used because it may have observable side-effects.

      void        ,void       undefined. 
      void        ,      。
    
    -      void
    >     ,  (void 0) === undefined,    undefined     ?
      undefined javascript      。   ,     :
    

    function joke() {
    var undefined = "hello world";
    console.log(undefined); // "hello world"
    }
    console.log(undefined); // undefined

      ,  void    undefined       。 underscore.js  isUndefined      :
    

    _.isUndefined = function(obj) {
    return obj === void 0;
    }

        void     undefined   ,       ?  ,             。 AngularJS           :
    

    (function(window, document, undefined) {
    //.....
    })(window, document);

          ,   undefined       undefined。
    
    -     
    >    undefined ,void        .
           `javascript:void(0);`  href。  ,     ,        ,                     ,           。
         ,          URL ,       ,          。      `href="javascript:void(0)`   ,               `void(0)`。
          ,           src image,         `src='javascript:void(0)'`,  StackOverflow      :[What’s the valid way to include an image with no src?](http://stackoverflow.com/questions/5775469/whats-the-valid-way-to-include-an-image-with-no-src)
    
    -     
    >   void   ,          :
    `NOTE: GetValue must be called even though its value is not used because it may have observable side-effects.`
          ?     void         ,      。         ,    winter      :[  js void,       undefined,  GetValue   ?](http://www.zhihu.com/question/22210634)
    

    var happiness = 10;
    var girl = {
    get whenMarry() {
    happiness--;
    return 1/0; //Infinity
    },
    get happiness() {
    return happiness;
    }
    };
    console.log(girl.whenMarry); // whenMarry get
    console.log(girl.happiness); // 9
    void girl.whenMarry; // whenMarry get
    console.log(girl.happiness); // 8
    delete girl.whenMarry; // whenMarry get
    console.log(girl.happiness); // 8

                    ,           (whenMarry),happiness   1。         ,       girl.whenMarry,  void girl.whenMarry     happiness--。    void  delete     delete girl.whenMarry,  happiness     ,  delete      girl.whenMarry  。
    
    -   
    > void     :
        void 0 undefined       undefined      ,      void 0    。
      \のhrefはクリック にページジャンプが  しないことを  します。  されたsrcは、サーバーにごみの  がないことを  する。