Posts

Showing posts with the label javascript

Logging messages to Javascript console

Image
If you have had experience of web development and have hands on javascript coding, you will know how difficult it becomes at times when you have to debug javascript code. And it gets worse when you have multiple browsers rendering the javascript in their own ways. I could remember debugging the javascript code manually by putting those crappy and irritating alert() messages in the code to know how the code is being executed to root cause the issue. And if you know what I am talking about, you will know what I am talking about. But browsers have evolved a lot is the last five years and so as the tools for web development. When I first started using the Web Developer addon , it was like I had waited for it since ages for it. And I still feel there is no match for it. Even though the javascript console was available in Firefox, with usage of Web Developer, it was more accessible than ever. Okay. Too much theory. Lets get to point. You need to debug javascript pages and get rid of those al...

Javascript - parseInt bug

Working in javascript on the my project, I found an interesting thing which I would like to share with you all. parseInt() method in javascript is used to parse a string text into integer. For example to convert String “8” as integer 8 for processing, you will use it as follows: var parsedValue = parseInt(“8”); You can find more details about the parseInt() method on W3C Schools. http://www.w3schools.com/jsref/jsref_parseInt.asp However, there is an interesting bug with parseInt(). When you try to parseInt("08") or parseInt("09"), it returns 0. This is because the leading zero tells the parseInt() method that it is an octal number and 08 is not a valid octal value. Hence the parsing returns 0 as output. So, you might get this scenario when you trying to parse date values or month values containing leading zeros. Workaround: - Use the alternate form of parseInt(value, radix). This form forces the parsing of the string value as per your radix value. 10 indicate for de...