proper use of parseInt is do that. parseInt(number, 10)  for 10-base.

On Tue, Feb 21, 2012 at 2:16 PM, Andrew Chilton <chi...@appsattic.com>wrote:

> On 22 February 2012 10:46, Tim Caswell <t...@creationix.com> wrote:
> > While it's annoying, it's a good idea to always specify the radix (the
> > second argument to parseInt) when parsing numbers and you know the
> > radix. This is why jslint yells at you if you leave this "optional"
> argument
> > off.
>
> On a slightly different note, another good way (which Crockford also
> suggests) is instead of using parseInt(), coerce the string into
> number by using +'08'. This will give you the number 8.
>
> Note that in your case this may not be what you want since it gives a
> number, not an integer. This is fine if you know your string contains
> a round number, but not if your string can contain a decimal point.
> e.g. +'08.5' will give you the number 8.5.
>
> If you ever use this in a calculation of some sort, it's also good to
> put parens around your coerce. For example:
>
>    var x = something + (+'08') + whatever;
>
> Cheers,
> Andy
>
> --
> Andrew Chilton
> e: chi...@appsattic.com
> w: http://www.appsattic.com/
>
> --
> 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 nodejs@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>

-- 
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 nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to