ExamVeda
Login
Home
This question belongs to Javascript Classes And Modules
Classes and Modules
?

Consider the following code snippet
function oddsums(n) 
{
     let total = 0, result=[]; 
     for(let x = 1; x <= n; x++) 
     { 
        let odd = 2*x-1; 
        total += odd;
        result.push(total);
     }
     return result;
}

What would be the output if
oddsums(5);
is executed afted the above code snippet ?

Answer & Solution
Correct Answer: Option A
The above code returns 1,4,9,16,25 which is the square of the first five natural numbers. Notice the usage of let keyword in the above code snippet.
Examveda
Question posted by Examveda
Community

Join the Discussion

No comments yet Be the first to discuss this question.