Reputation: 8734
Is there a way to check if something is bigint
type?
I would like to check this:
99999999999999999999999999999999999999999999999999
I know this number can't be represented as an Integer. How can I check if it can be represented as a bigint?
If I use the typeof
on it, it says number
.
Also is there any way to specify a type with a decimal at the end?
example: 99999999999999999999999999999999999999999999999999.99
Upvotes: 1
Views: 1785
Reputation: 91
You can use Number.MAX_SAFE_INTEGER to check if is a bigint or not. Link below: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER
or a better way: Number.isSafeInteger() https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger
Upvotes: 1