If you can't use expression forces Java Script to do type coercion on your input value; it must first be interpreted as a number for the subtraction operation.
If that conversion to a number fails, the expression will result in result is then compared to the original value you passed in.
Running the unit tests against the new code and it only fails on the infinity and boolean literals, and the only time that should be a problem is if you're generating code (really, who would type in a literal and check if it's numeric? It's definitely not the shortest possible regular expression, but I believe it catches all the finer subtleties of Java Script's number syntax.
You should The accepted answer failed your test #7 and I guess it's because you changed your mind. function is Number(n) function is Finite Number(n) function is Comparable Number(n) is Finite Number('Na N') false is Finite Number('Ox FF') true is Number('Na N') true is Number(1/0-1/0) true is Comparable Number('Na N') false is Comparable Number('Infinity') true Explained: Create a copy of itself, then converts the number into float, then compares itself with the original number, if it is still a number, (whether integer or float) , and matches the original number, that means, it is indeed a number. I realize this has been answered many times, but the following is a decent candidate which can be useful in some scenarios.
It is unit tested with 100% code coverage and can be considered fit for production.
The project can be found on Git Hub where you can also find our issue tracker.
In our example, we have a login form with two input fields i.e.