-
-
Save ApolloTang/6b3593dab1c19d081edc27f7dd5639aa 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 nothing. | |
**/ | |
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