Debugging JavaScript code is no pleasant task. Debuggers are buggy, logging libraries are unreliable and the whole experience is generally very time consuming, especially for someone who’s used to the Java way of doing things. During my long and painful session of debugging wild1 JavaScript code, I always knew I could save a lot of [...]
Debugging JavaScript code is no pleasant task. Debuggers are buggy, logging libraries are unreliable and the whole experience is generally very time consuming, especially for someone who’s used to the Java way of doing things. During my long and painful session of debugging wild1 JavaScript code, I always knew I could save a lot of time if JavaScript had the equivalent of Java’s ubiquitous toString method or PHP’s useful print_r function.
Apparently I’m not alone. Dutch blogger Kevin van Zonneveld is leading a project called php.js, which aims to port as many PHP functions as possible to JavaScript. One of those functions is print_r, which “[p]rints human-readable information about a variable”. It takes a variable of any data type, and prints it (including any fields it may contain) in a format well suited for debugging purposes. Plus, it doesn’t depend on any library or framework. This one definitely joins my JS toolkit.
It’s licensed under the liberal MIT license.
1Wild site is a term used internally at Creative Calls to refer to a web page that’s out there on the web, as opposed to a page produced by our system and under our control. The term was borrowed from the world of computer viruses.




