-2
なぜこの関数は "old"ではなくundefined
を返しますか?私の条件演算子はなぜ機能しませんか?
function test(age) {
12 < age ? "old" : "young";
}
test(15);
なぜこの関数は "old"ではなくundefined
を返しますか?私の条件演算子はなぜ機能しませんか?
function test(age) {
12 < age ? "old" : "young";
}
test(15);
条件は問題ありません。あなたはreturn
文をオフのままにするとreturn
function test(age) {
return 12 < age ? "old" : "young";
}
console.log(test(15));
に必要な、機能はデフォルトでundefined
を返します。
これは有効なjavascriptではないためです。 http://stackoverflow.com/questions/11069278/javascript-if-else-shorthand – dahrens
実際には有効なjavascript –