javascript - Why doesn't my conditional operator work? -
why function return undefined instead of "old"?
function test(age) { 12 < age ? "old" : "young"; } test(15);
your condition fine. need return
function test(age) { return 12 < age ? "old" : "young"; } console.log(test(15)); when leave off return statement, function returns undefined default.
Comments
Post a Comment