Fun with semicolons in JavaScript
So people always say that in JavaScript semicolons are optional but you had better use them anyway. The often cited case is the return statement.
In JavaScript you can make new code block “{ }” anywhere you want and it is perfectly valid, it will just execute when the code path hits it. Another funny thing is that for some reason an if without a body and semicolon following it is valid (e.g. “if(true);” will not throw any error). So if you bring these two things together you can get a weird thing like this:
Written on December 30, 2015