function sum() { let num = 0; for (let i = 0; i < arguments.length; i++) { //注意:typeof(NaN) => 'number',但是 (NaN === NaN) => false if (typeof (arguments[i]) === 'number' && parseFloat(arguments[i]) === parseFloat(arguments[i])) { num += arguments[i] } } return num } console.log(sum(1, 2.5, 3.8, '2px', 54, true, '', function () {}, {}, '2', NaN, -1 )); //61.3