> +'123 px'
> NaN
And that is exactly correct. '123 px' is not a number. Using that
"feature" is worse than trusting type coercion. I would never trust that
in my code, just as I always use === instead of ==. Well actually I use
"is" in coffee, but that is a different subject.
What if your string was accidentally "100%" instead of "100 px"?
You said nothing is right for me. I'm just pointing out that was an overly
broad statement. Using + instead of parseInt *is* exactly right for me.
If you want to be able to use '010' to represent 8 and '1xyz' to represent
1, then more power to you. I myself will never use parseInt. Not only for
the behavior but because it takes too much typing, is less succinct and
therefore is less readable.
Compare...
area = +w * +h
To ...
area = parseInt(w, 10) * parseInt(h, 10)
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en