Showing posts with label fun with javascript. Show all posts
Showing posts with label fun with javascript. Show all posts

Thursday, August 28, 2014

Example for Closure, .call, .apply in javascript


function add(y,z){ 
function fn(x,y,z){ 
console.log(Math.round(x+y)*z);
};
fn(this.x,y,z);
};

add.call({x: 20.1},3.1,5.1);  // 117.3
add.apply({x: 20.1},[3.1,5.1]);  // 117.3

Wednesday, July 30, 2014

Strangest things i found in JavaScript


  1. [] + []; // ""
  2. {} + {}; // NaN
  3. [] + {}; // "[object Object]"
  4. {} + []; // 0
  5. [] == []; // false
  6. [] < []; // false
  7. [] > []; // false
  8. [] <= []; // true
  9. [] >= []; //true
  10. Math.min() < Math.max(); // false
  11. foo = [0];
  12. !foo; // false
  13. foo == foo; // true
  14. foo == !foo; // true
  15. [['0']] == false; // true
  16. [['0']] == true; // false
  17. typeof NaN; // "number"
  18. NaN == true; // false
  19. NaN == false; // false
  20. NaN != true; // true
  21. NaN != false; // true
  22. NaN == NaN; // false
  23. NaN == !NaN; // false
  24. !NaN; // true
  25. NaN != NaN; // true
  26. 'x' == true; // true
  27. 'x' == false; // false
  28. '0' == true; // false
  29. '0' == false; // true