var printNumTwo;
for (var i = 0; i < 3; i++) {
if (i === 2) {
printNumTwo = function() {
return i;
};
}
}
console.log(printNumTwo());
This is the 3rd code snippet under " Compare Scopes of the var and let Keywords
I dont understand why printNumTwo has ‘()’ in console.log() in last statement.
printNumTwo
is a function. The ()
s call the function.
isnt it declared as var, and then assigned the value of function() ?
A function is stored in a variable just like any other type of JS object.
You can read about this function definition syntax here:
system
Closed
5
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.