在JavaScript中使用isNaN()检查非法数字
以下是代码-
示例
function multiplication(firstValue, secondValue, callback) {
var res = firstValue * secondValue;
var err = isNaN(res) ? 'Something is wrong in input parameter' :
undefined;
callback(res, err);
}
multiplication(10, 50, function (result, error) {
console.log("The multiplication result="+result);
if (error) {
console.log(error);
}
});
multiplication('Sam', 5, function (result, error) {
console.log("The multiplication result="+result);
if (error) {
console.log(error);
}
});要运行上述程序,您需要使用以下命令-
node fileName.js.
在这里,我的文件名为demo201.js。
输出结果
这将产生以下输出-
PS C:\Users\Amit\javascript-code> node demo201.js The multiplication result=500 The multiplication result=NaN Something is wrong in input parameter
热门推荐
10 分别发的祝福语简短
11 大外甥高考祝福语简短
12 小学毕业校长简短祝福语
13 搞工程发财祝福语简短
14 冬季祝福语男生文案简短
15 同事生子问候祝福语简短
16 退休文案寄语简短祝福语
17 送给自己的祝福语简短
18 简短祝福语毛笔字