「JavaScript」isNaN() 関数のサンプル

2020年10月11日

構文
isNaN(value)
引数
value
テストされる値。
返値
もし引数が NaN であるならば true を返し, そうでなければ false を返します。
JSコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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

JavaScript

Posted by arkgame