Showing posts with label Yahoo. Show all posts
Showing posts with label Yahoo. Show all posts

Friday, January 4, 2013

Wednesday, January 2, 2013

Short JavaScript Quiz

Give the output of  the following and define the scope of variables

<script>


// a _____-scoped variable
var a=1;

// ______ scope
function one(){
    alert(a); 
}

// ______ scope
function two(a){
    alert(a);
}

// ______ scope
function three(){
  var a = 3;
  alert(a);
}

// Intermediate: 
Does javascript have a block scope ?
function four(){
    if(true){
        var a=4;
    }

    alert(a);
}


// Intermediate:  ______ ______ properties
function Five(){
    this.a = 5;
}


// Advanced: closure
var six = function(){
    var foo = 6;

    return function(){
        // javascript - "closure" means I have access to foo in here,
        // [ to be updated ]
        alert(foo);
    }
}()


// Advanced: __________ scope resolution
function Seven(){
  this.a = 7;
}

// [object].______ loses to [object].______ in the scope chain
Seven.prototype.a = -1; // ______ get reached, because __ is __ in the constructor above.
Seven.prototype.b = 8; // ______ get reached, even though __ is ___ set in the constructor.


one();
two(2);
three();
four();
alert(new Five().a);
six();
alert(new Seven().a);
alert(new Seven().b);


</script>
The best ever examples given by Triptych - on Stackoverflow.com
Source:
http://stackoverflow.com/questions/500431/javascript-variable-scope

Saturday, December 22, 2012

Question 2

What happens when you type in a url in your browser ?

http://interactioncloud.blogspot.com/2012/12/behind-browser.html

Tuesday, December 18, 2012

Question 1


Given co-ordinates (x1,y1),(x2,y2) and (x3,y3),(x4,4). Check if two rectangles overlap.

0 if they overlap
1 if they do not overlap

hint: no need to use distance formulae