Logging messages to Javascript console

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 alert() statements. Here is what you need. Today, browsers come along with a javascript console. And you can log messages to them by using the console object.

Here is what you will need to write to log messages to console.

<script type="text/javascript" language="javascript">
for ( var i = 0; i < 5; i++ ) {
console.log("Log message - " + i);
}
</script>


However, you will need to use some addons for those. If you are a Firefox lover (my buddy), you might know about Firebug. Install it. It's a web developer's true true mate. Here is a screenshot.





For that pathetic IE (sorry if you love it), you need to have IE 7+ version and need to install IE Developer Toolbar to access that.


Comments

Popular posts from this blog

Personal Contact Manager

An apt quote

Alone