💾isNumber()

test if a value is a valid number.

JSvalueprimitivenumberfunctions ⟩ isNumber()

determine if a value is a (valid) number, equivalent to Number.isFinite(x).

// ⭐️ is (valid) number?
function isNumber(value) {
    return Number.isFinite(value);
}

// export
module.exports = { isNumber };

💈範例:

value  isNumber()?   Number.isFinite()?
---------------------------------------------
123       ✅         ✅                 
-2.5      ✅         ✅                 
Infinity  ❌         ❌                 
NaN       ❌         ❌                 
'123'     ❌         ❌                 
''        ❌         ❌         empty string
---------------------------------------------

Last updated