3 ms·
JavaScript debugging for beginners
- mvclark 12y agoNice post. Another one I find useful is to define your own log function, e.g., function log(x) {console.log(x);}; You'd use log instead of console.log for debugging your code. Then, to turn off logging, you set function log(x) {}; or have a boolean switch in log function to do a similar thing. You could even use this approach to define debug levels to enable/disable.
- jasode 12y agoInstead of Ctrl+Shift+I, I usually use F12 because it works in all 3 browsers Chrome, Firefox, and IE. In IE, Ctrl+Shift+I brings up Favorites/Feeds/History. However, on Mac OSX, Ctrl+Shift+I makes more sense because the default for F12 is to adjust sound volume up. You have to press Fn+F12 which is more awkward than Ctrl+Shift+I. (Or Cmd+Alt+I in Safari).
- mkoryak 12y agoNice article. Not just for beginners either. Ive been debugging javascript since IE6 and didnt know about "If you click the braces at the bottom of the developer tools, they will “pretty print” the code. It makes it a little bit more readable, but it’s still difficult to decipher. (granted, javascript consoles were a bit different back then: http://notetodogself.blogspot.com/2008/08/debug-javascript-in-ie.html http://notetodogself.blogspot.com/2008/08/debug-javascript-i...)