[英]How do I check if my scope variable actually contains NaN?
How do i check if my scope variable actually contains NaN? 如何检查我的范围变量是否实际包含NaN?
isNaN($scope.variable)
returns true even if $scope.variable == undefined.
即使
$scope.variable == undefined.
isNaN($scope.variable)
返回true $scope.variable == undefined.
I want to set form validity
true if scope variable actually contains NaN
but not undefined
. 如果范围变量实际上包含
NaN
但undefined
我想将form validity
设置为true。
Well the problem is that isNaN converts argument to Number type if it's not a number already, and since ToNumber(undefined)
is indeed NaN
you get this behavior. 那么问题是isNaN将参数转换为Number类型,如果它已经不是数字,并且由于
ToNumber(undefined)
确实是NaN
你会得到这种行为。
So you can Number.isNaN() which was introduced in ES2015 to fix this confusion or add additional check whether the value is of Number type, so basically polyfilling this Number.isNaN
: 因此,您可以在ES2015中引入的Number.isNaN()来修复此混淆或添加额外检查值是否为Number类型,因此基本上
Number.isNaN
此Number.isNaN
:
$scope.variable == undefined.
// ...
typeof $scope.variable == 'number' && isNaN($scope.variable); // => false
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.