Javascript Oddities or Things your learn the hard way

Did you know…

  • NaN is not equal to NaN
  • null is equal to undefined
  • Infinity divided by Infinity equals NaN
  • Infinity multiplied by Infinity equals Infinity
  • When the script begins to execute:
    1. All declared functions (i.e. function myFunction () {} ) are hoisted to the top of their scope
    2. All declared variables (i.e. var myVar;) are hoisted below them
    3. All the variable initialization (i.e myVar = 1;) and function expressions (i.e. myFunction = function () {} ) are executed in order
    4. All global variables are properties of the Window object
    5. You cannot delete a variable from within a function
  • This expression

    (function (x) {
    return x;
    }) (1);

    An anonymous function within brackets followed by brackets that may contain its argument, is simply executeing itself at runtime.

    function myFunction (x) {
    return x;
    var a = myFunction(1);