Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Question: Tell us about local variables.
Answer: If needed, you can declare local variables within a function.

local variable is visible only within the function body after it’s declared.

Commonly used to store results of an intermediate calculation.

function findMaxValue(num1, num2,num3) {
var tempMax; //local var

if (num1 >= num2) {
tempMax = num1;
}

else {
tempMax = num2;
}

if(num3 >= tempMax) {
tempMax = num3;
}

return tempMax;

} //end function
Is it helpful? Yes No

Most helpful rated by users:

©2025 WithoutBook