Sunday, August 30, 2015

JavaScript amazing facts

JavaScript is the most used language of this time on the planet earth.

  1. Everything is object in JavaScript, even function is also a first class object.
    • You can pass function object as an argument to a function
    • Function object can be returned from a function
    • Function may assigned to a variable
    • Function May be stored in an object or array
  2. JavaScript programs use Unicode character set (UTF-16) which is super-set of ASCII and Latin-1 and supports virtually every written language currently used on the planet
  3. NULL is an object in JavaScript
  4. NaN is a number, if we say typeof NaN, then it would be number
  5. typeof Infinity is a number
  6. Function can execute themselves. We call them self executing function. This is very important concept/feature which is used at many places
  7. using typeof we can not get if any variable is of type array. So how we can determine if a variable is of type array?
    var ar = [1,2,3];
    ar instanceof Array // this will return true because ar is of type array
    
    There is one more way to get the type of any variable:
    var ar = [1,2,3];
    Object.prototype.toString.call(ar); // "[object Array]"
    

No comments:

Post a Comment