var cheese; ( ). , var cheese = undefined;, ...
var , : .
:
var cheese: ?.
Answer: it may be good that your algorithm returns cheesewithout assigning it anything, i.e. " undefinedis valid."
Here is an example that illustrates how to varhide variables from parent areas:
var a = 3;
console.log(a);
function findEvenNumber(numbers) {
var a;
numbers.forEach(function(number) {
if (number % 2 === 0) {
a = number;
}
});
return a;
}
findEvenNumber([1, 2]);
console.log(a);
Speculation: there may be syntax in ECMA var cheese;that allows programmers to declare all variables at the beginning of their function. This convention was applied by the C89 compiler , and some people loved it.
source
share