//判断输入是否是数字
function cube(x) {
if (typeof(x) != 'number') return 0;
return x * x * x;
}
// Once you uncomment the type check in line 2, the
// cube function should return 0.
cube("test");
本文介绍了如何使用JavaScript判断输入是否为数字,并通过实例演示了如何实现数字立方函数,同时在函数调用时进行类型检查,确保返回正确的立方结果。
//判断输入是否是数字
function cube(x) {
if (typeof(x) != 'number') return 0;
return x * x * x;
}
// Once you uncomment the type check in line 2, the
// cube function should return 0.
cube("test");
1627
2万+

被折叠的 条评论
为什么被折叠?