ExamVeda
Login
Home
This question belongs to Javascript Array And Function
Array and Function
?

Consider the following code snippet
function hypotenuse(a, b) 
{
  function square(x) 
  { 
    return x*x; 
  }
  return Math.sqrt(square(a) + square(b));
}
What does the above code result?

Answer & Solution
Correct Answer: Option A
The above code snippet contains nested function in which the function hypotenuse(a,b) has another function inside its scope, function square(x). The interesting thing about nested functions is their variable scoping rules. They can acceess the parameters and variables of the function (or functions) they are nested within.
Examveda
Question posted by Examveda
Community

Join the Discussion

No comments yet Be the first to discuss this question.