Wednesday, December 18, 2013

Javascript Puzzle - 2

12:33 AM Posted by Unknown , , , 1 comment
Courtesy: A Javascript conference video. I forgot the name of the conference. Will update.

var name = 'Mr. Bond';

    (function(){
      if(typeof name === 'undefined'){
          var name = "Mr. Bond";
          sayHello(name);
      } else {
           alert(name);
       }
})();

function sayHello(name){
    alert('hello, ' + typeof name !== 'undefined'? name: 'Mr. Robert!');
}

What this alerts? And, give me the reason for that.

JavaScript Puzzle - 1

12:29 AM Posted by Unknown , , , No comments
Courtesy: A Javascript conference video. I forgot the name of the conference. Will update.

var END = 9007199254740992; //Math.pow(2,53)
  var START = END - 100;

var count = 0;
for(var i = START; i<= END; i++){
   count++;
}

alert(count);


What this alerts? And, give me the reason for that.