2 quick Javascript tips

1. Out-of-the-box pretty printing JSON Have you ever had the need to print out a JSON structure for debugging? Something like:

console.log("the data is:", JSON.stringify(data));

And then the result is a unformatted JSON structure that you copy/paste into your editor for prettyprinting? Well there is a way to avoid that last step. Just pass in two more magic arguments to JSON.stringify and you get prettyprinted JSON right out of the box.

console.log("the data is:", JSON.stringify(data, null, 2));

2. Programmatically set debug breakpoint If you have minified concatenated Javascript it can sometime be difficult to find the code in Chrome to be able to set a breakpoint at the correct place when you need to debug. The good thing is that you can set the breakpoint in your code with the following statement: