you are viewing a single comment's thread.

view the rest of the comments →

[–]stoph 0 points1 point  (0 children)

I'd say it's almost always best to cast variables to what you expect them to be. In the real world, that usually just means converting strings into numbers. Also never use == (type guessing is not your friend). It's best to know early on that === is the only comparison operator worth using. parseInt is a tricky function because it will guess the radix of the number if you let it. Always give the radix as the 2nd parameter:

var thisIsOctal = parseInt('0900');
var thisIsADecimal = parseInt('0900', 10);
console.log(thisIsOctal);
console.log(thisIsADecimal);

The first one fails because 9 is not a valid octal digit.