Last active
July 24, 2017 13:24
-
-
Save tekaratzas/ecb4f58f98bd46252f078bf7926175b3 to your computer and use it in GitHub Desktop.
Semi-Colon Hell Javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Here, the parser will add a semi colon after return causing the function to return undefined. | |
**/ | |
function test(){ | |
var name = "Hello"; | |
return // it will add a ; here | |
{ | |
name: name | |
} | |
} | |
/** | |
This one is even weirder..... | |
It does't add it in the case of a leading parenthesis | |
You end up with a type error since is assumes "console.log()" is a function and (someList || []) is its parameter | |
**/ | |
function test2(){ | |
var someList = undefined | |
console.log("Hi!") // does not add it here! | |
(someList || []).map((item) => item) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment