【发布时间】:2021-05-30 13:11:31
【问题描述】:
我想检查一个数字是否是大小可接受的 BigInt if 语句
我知道有解决办法
function isBigInt(x) {
try {
return BigInt(x) === x; // dont use == because 7 == 7n but 7 !== 7n
} catch(error) {
return false; // conversion to BigInt failed, surely it is not a BigInt
}
}
但我想直接在我的 if 语句中实现测试,而不是在我的函数中
有人可以帮我吗?
【问题讨论】:
-
您可以在 if 语句中插入函数调用。
标签: javascript bigint