Home » JavaScript » JavaScript Functions » Question
  1. Consider the following code snippet
    function hypotenuse(p, q) 
    {
    function square(n)
    {
    return n*n;
    }
    return Math.sqrt(square(p) + square(q));
    }

    What does the above code result?
    1. Square of sum of p and q
    2. Sum of p and q square
    3. Sum of square of p and q
    4. All of above
    5. None of these
Correct Option: C

The above code snippet contains nested function in which the function hypotenuse(p,q) has another function inside its scope, function square(n). The interesting thing about nested functions is their variable scoping rules. They can access the parameters and variables of the function (or functions) they are nested within.



Your comments will be displayed only after manual approval.