{"id":86,"date":"2008-10-02T21:29:21","date_gmt":"2008-10-03T02:29:21","guid":{"rendered":"http:\/\/osric.com\/chris\/accidental-developer\/?p=86"},"modified":"2009-04-09T10:13:41","modified_gmt":"2009-04-09T15:13:41","slug":"javascripts-parseint-is-pretty-evil","status":"publish","type":"post","link":"https:\/\/osric.com\/chris\/accidental-developer\/2008\/10\/javascripts-parseint-is-pretty-evil\/","title":{"rendered":"javascript&#8217;s parseInt is pretty evil"},"content":{"rendered":"<p>Javascript uses the + symbol for both addition and concatenation. This means that if you want to add a numeric value to data pulled from a user, you need to cast it to being a numeric type, like for instance an Int. Makes sense, so I use the parseInt function to cast with. OK, that&#8217;s fine so here is the kicker, if you pass it &#8220;09&#8221; it generates the value 0, not 9. <\/p>\n<p>Hrmm, well that&#8217;s odd. If you pass in &#8220;9&#8221; it returns 9, but if you pass in &#8220;09&#8221; you get 0. I&#8217;m lucky I caught that in testing. It turns out that if you lead with a 0 then parseInt interprates as the value as an octal number. There is a way to deal with it though, you can pass in a second variable telling it what base the numbers it should be reading are. <\/p>\n<p>So really you want parseInt(var, 10) not parseInt(var)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Javascript uses the + symbol for both addition and concatenation. This means that if you want to add a numeric value to data pulled from a user, you need to cast it to being a numeric type, like for instance an Int. Makes sense, so I use the parseInt function to cast with. OK, that&#8217;s &hellip; <a href=\"https:\/\/osric.com\/chris\/accidental-developer\/2008\/10\/javascripts-parseint-is-pretty-evil\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">javascript&#8217;s parseInt is pretty evil<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[66],"class_list":["post-86","post","type-post","status-publish","format-standard","hentry","category-javascript","tag-parseint"],"_links":{"self":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/86","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/comments?post=86"}],"version-history":[{"count":2,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/86\/revisions"}],"predecessor-version":[{"id":163,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/86\/revisions\/163"}],"wp:attachment":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/media?parent=86"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/categories?post=86"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/tags?post=86"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}