dave.methvin wrote:
> 
>> Just discovered your "use unary operator" tip
>> (http://www.javascripttoolbox.com/bestpractices/#plus).
>> Great! Much more succinct then a parseInt(value).
> Be very careful using the + operator this way.
>  +"32px" returns NaN
>  parseInt("32px") returns 32
> 

True, but in this case you aren't really type-converting to a number, you're
actually wanting to extract a number from a string. That's a different case.
And someone might then wonder why they try parseInt("10.5em") but it doesn't
work as expected.

And one of the main reasons to recommend + over parseInt() is because many
people try to do parseInt('09') and get the wrong result and can't figure
out why. In this case, +"09" works as expected.

Matt

-- 
View this message in context: 
http://www.nabble.com/jQuery-Design-Decisions--Comparison-to-MooTools--tf3218550.html#a8953990
Sent from the JQuery mailing list archive at Nabble.com.


_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to