Page 192 - JavaScript
P. 192

}

         console.log( foo('burger') );  // burger
         console.log( foo(100) );       // 100
         console.log( foo([]) );        // []
         console.log( foo(0) );         // default
         console.log( foo(undefined) ); // default


        Just keep in mind that for arguments, 0 and (to a lesser extent) the empty string are also often
        valid values that should be able to be explicitly passed and override a default, which, with this
        pattern, they won’t (because they are falsy).

        Null and Undefined




        The differences between null and undefined



        null and undefined share abstract equality == but not strict equality ===,


         null == undefined   // true
         null === undefined  // false


        They represent slightly different things:


            •  undefined represents the absence of a value, such as before an identifier/Object property has
              been created or in the period between identifier/Function parameter creation and it's first set,
              if any.
            •  null represents the intentional absence of a value for an identifier or property which has
              already been created.

        They are different types of syntax:


            •  undefined is a property of the global Object, usually immutable in the global scope. This
              means anywhere you can define an identifier other than in the global namespace could hide
              undefined from that scope (although things can still be undefined)
            •  null is a word literal, so it's meaning can never be changed and attempting to do so will
              throw an Error.




        The similarities between null and undefined


        null and undefined are both falsy.


         if (null) console.log("won't be logged");
         if (undefined) console.log("won't be logged");


        Neither null or undefined equal false (see this question).


         false == undefined   // false



        https://riptutorial.com/                                                                             149
   187   188   189   190   191   192   193   194   195   196   197