local variable sum, couldn't fetched
without var keyword, var sum became global

then it can be fetched using console.log.

otherwise var sum within a function will be local to the function's
scope
sum will show its last value

correction of logging the variable
introducing closure = nested function