xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

how to check a var whether is number in js

how to check a var whether is number in js

js check var is number


Number.isInteger(NaN)
false
Number.isInteger(``)
false
Number.isInteger(0)
true
Number.isInteger(null)
false
Number.isInteger(undefined)
false

typeof === "number"

typeof NaN;
// "number"

typeof undefined;
// "undefined"
typeof ``;

// "string"
typeof null;
// "object"

let x = NaN;
// NaN

isNaN(x);
// true

isNaN(0);
// false

isNaN(``);
// false

isNaN(null);
// false

isNaN(undefined);
// true

https://mkyong.com/javascript/check-if-variable-is-a-number-in-javascript/

https://dev.to/skptricks/check-if-variable-is-a-number-in-javascript-1f10

https://www.skptricks.com/2018/11/check-if-variable-is-number-in-js.html

https://medium.com/javascript-in-plain-english/how-to-check-for-a-number-in-javascript-8d9024708153

https://www.w3schools.com/jsref/jsref_isnan.asp


TS

https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html


posted @ 2020-03-20 00:55  xgqfrms  阅读(193)  评论(5编辑  收藏  举报