DEV Community

Md Abdul Momin
Md Abdul Momin

Posted on

Which one is valid ? How can answer 15 for both ?

01


function doSomething(a) {
    b = a + doSomethingElse( a * 2 );

    console.log( b * 3 );
}

function doSomethingElse(a) {
    return a - 1;
}

var b;

doSomething( 2 ); // 15
Enter fullscreen mode Exit fullscreen mode

02

function doSomething(a) {
    function doSomethingElse(a) {
        return a - 1;
    }

    var b;

    b = a + doSomethingElse( a * 2 );

    console.log( b * 3 );
}

doSomething( 2 ); // 15
Enter fullscreen mode Exit fullscreen mode

Top comments (0)