3 ms·
"Es6 and typescript fixes all this." ES6 doesn't fix any of it, typescript fixes some of it.
by jomamaxx 10y ago
"Es6 and typescript fixes all this."
ES6 doesn't fix any of it, typescript fixes some of it.
- Arnavion 10y agoES6 adds isNaN and isFinite static methods to Number that don't convert their argument to a number first, so Klathmon's version works. But I don't make any claim about whether it's correct or not. https://babeljs.io/repl/#?babili=false&evaluate=true&lineWrap=false&presets=es2015%2Creact%2Cstage-2&code=function%20isNumber(arg)%20%7B%0A%20%20return%20!Number.isNaN(arg)%20%26%26%20Number.isFinite(arg)%3B%0A%7D%0A%0Aconsole.log(isNumber(100))%3B%0Aconsole.log(isNumber('100'))%3B%0Aconsole.log(isNumber(undefined))%3B%0Aconsole.log(isNumber(null))%3B%0A https://babeljs.io/repl/#?babili=false&evaluate=true&lineWra... Compare step 1 of http://www.ecma-international.org/ecma-262/6.0/#sec-isnan-number http://www.ecma-international.org/ecma-262/6.0/#sec-isnan-nu... with http://www.ecma-international.org/ecma-262/6.0/#sec-number.isnan http://www.ecma-international.org/ecma-262/6.0/#sec-number.i...