Using parseInt() is a bad idea mainly because it never fails. Also because some results can be unexpected :

```
parseInt('09', 10);
// return 0 on firefox, nodejs
```

### What I use instead :

```
function cleanInt(x) {
x = Number(x);
return x >= 0 ? Math.floor(x) : Math.ceil(x);
}
```

### Why should I do this way ?

*if the text is not a number (like "123abc") it returns NaN. It seems for me a better behavior. Also, the function can deal with Infinity which is also a number.*

```
parseInt('123abc',10); //return 123
cleanInt('123abc'); //return NaN
parseInt('Infinity',10); //return NaN
cleanInt('Infinity') //return Infinity
typeof cleanInt('Infinity') // return "number"
```

parseInt works correctly, please look at the docs.

String representations starting with "0" are considered

octalnumbers. So`parseInt('09')`

starts parsing '09' as octal and stops when if encounters an invalid character ('9' in this case) so you get 0 as result.Always use the second parameter (radix) with parseInt:

Browsers like Chrome seem to always assume 10 as default value of the second parameter but you must not rely on that.

Btw, another simple way of converting String to Number is the following:

'09'*1; // 9

It will even work with floats:

If you only want integer part, you can use a bitwise operator:

No quirks that I know of...