Monday, July 18, 2016

JavaScript - Bind

function getCount() {
    return this.myCount++;
}


> var counter2 = getCount.bind({myCount:100});
undefined
> counter2()
100
> counter2()
101

JavaScript - Closure



mycount variable act as Global variable

function getCounter() {
   var myCount = 0;
   return function() {
        return myCount++;
    }
}

counter = getCounter();


> counter();
0
> counter();
1

JavaScript - Arguments

JavaScript function without defining parameters

function add() {
    var result = 0;
    for (var i = 0; i < arguments.length; i++) {
        result = result + arguments[i];
    }
    return result;
}


Result :
> add(3,7,8,10)
28

Thursday, July 14, 2016

What is the difference between div and span

div is block element.

span is same as div, except it is an inline.