「JavaScript」isNaN() 関数のサンプル
構文
isNaN(value)
引数
value
テストされる値。
返値
もし引数が NaN であるならば true を返し, そうでなければ false を返します。
JSコード
function test(x) {
if (isNaN(x)) {
return 'xは数値ではない';
}
return x * 100;
}
console.log(test('20F'));
console.log(test('0.23'));
function test(x) {
if (isNaN(x)) {
return 'xは数値ではない';
}
return x * 100;
}
console.log(test('20F'));
console.log(test('0.23'));
function test(x) { if (isNaN(x)) { return 'xは数値ではない'; } return x * 100; } console.log(test('20F')); console.log(test('0.23'));
実行結果
“xは数値ではない"
23