0 == “0”, even though 0 is falsy and “0” is truthy
At first sight, this is very odd, but once you read more about the comparison operators this make sense. To avoid misunderstandings like this one, be sure to always use the strictly equal operator (===) to do this type of comparison. Lous Lazaris wrote an entire article on the unpredictable results that can occur when the equality comparison operator is not used the right way.
1+2+”3” != “1”+”2”+3
Omitting the var keyword
The semicolon is optional, but…
undefined, due the automatic semicolon injection.
The console is your friend
log() being by far the most known.
I think the
console.log() doesn’t need any introduction anymore, its non-blocking behavior and nice formatting was a big plus comparing with
alert(). The issue here is that, even though the
console.log was implemented in IE8 and IE9, the
console object somehow is not created until you toggle the DevTools.
So, found out on my own skin that if you let any
console.log calls in your code, it will break your code on browsers like IE8 and IE9. After browsing for a solution, I found the following as a good and simple solution. Basically, if the
window object does not have access to browser’s debugging console, just override the
console.log with a dummy function that does nothing at all.
Colorful log messages
But if logging methods like
error & warn are not enough to to distinguish your messages, you can try adding your own styling to the
Debugging with console.table()
Again, if using
console.table(). A very nice feature of console.table() is that it also works with objects.