Why does this function return undefined
instead of "old"?
function test(age) {
12 < age ? "old" : "young";
}
test(15);
Why does this function return undefined
instead of "old"?
function test(age) {
12 < age ? "old" : "young";
}
test(15);
Your condition is fine. You need to return
function test(age) {
return 12 < age ? "old" : "young";
}
console.log(test(15));
When you leave off a return
statement, a function returns undefined
by default.