πŸ“Š JavaScript
Q. 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?
  • (A) Sum of square of a and b
  • (B) Square of sum of a and b
  • (C) Sum of a and b square
  • (D) None of the mentioned
πŸ’¬ Discuss
βœ… Correct Answer: (A) Sum of square of a and b

Explanation: 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.

Explanation by: Mr. Dubey
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.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
119
Total Visits
πŸ“½οΈ
2 y ago
Published
πŸŽ–οΈ
Mr. Dubey
Publisher
πŸ“ˆ
99%
Success Rate