Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
114
rated 0 times [  116] [ 2]  / answers: 1 / hits: 49331  / 13 Years ago, fri, november 4, 2011, 12:00:00

Is there any difference between $.isNumeric and !isNaN()?



I don't see where they will ever return different results.


More From » jquery

 Answers
11

From the jQuery blog:




Inside jQuery we’ve found several situations where we need to know if an argument is numeric, or would be successfully converted to a number if it is some other type. We decided to write and document jQuery.isNumeric() since it’s a useful utility. Pass it an argument of any type and it returns true or false as appropriate.








jQuery.isNaN(): This undocumented utility function has been removed. It was confusing because it appropriated the name of a built-in JavaScript function but did not have the same semantics. The new jQuery.isNumeric() serves a similar purpose, but has the benefit of being documented and supported. Despite jQuery.isNaN() being undocumented, several projects on Github were using it. We have contacted them and asked that they use jQuery.isNumeric() or some other solution.




Also see the ticket: http://bugs.jquery.com/ticket/10478






jQuery's isNumeric() checks if a value is a number OR can be converted to a number.



EDIT



To further clarify what isNan() does (and what a NaN value is):




A NaN, which means Not-a-Number, is classified as a primitive value by the ECMA-262 standard and indicates that the specified value is not a legal number. The function returns true if the argument is not a number and false if the argument is a number.



The classic example of a NaN is zero divided by zero, 0/0




Code: 
document.write(isNaN(Ima String))
document.write(isNaN(0/0))
document.write(isNaN(348))
document.write(isNaN(348))

Output:
true
true
false
false


http://www.devguru.com/technologies/ecmascript/quickref/isnan.html



Semi offtopic, but related is this short talk


[#89297] Wednesday, November 2, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
samir

Total Points: 145
Total Questions: 90
Total Answers: 89

Location: Tokelau
Member since Sun, May 7, 2023
1 Year ago
;