WTF does this code do?benvan.co.uk 10 pointsbenvan12 years ago8 commentsSaveHideCopy link On HNComments−sigvef12yThis is why you should always use semicolons in JavaScript. Omitting semicolons here turns this: var angry = say('Garrrr!') // what should I say? (amIHappy ? happy : angry)() into this: var angry = say('Garrrr!')(amIHappy ? happy : angry)()−zequel12yMost web browsers (if you're running this code in a web browser), will do ASI (automatic semicolon insertion).http://jsfiddle.net/CxUXh/ works fine in Chrome, changing the console.log to an alert.Not that I'm advocating omitting semicolons!−benvanOP12yInteresting - your jsfiddle exhibits broken behaviour (alerting 'garrr') on my browser - chrome 33.0.1750.152. I believe I'm fairly up to date.−zequel12yYou're correct, I thought that was expected behavior, my mistake. TBH though, I'm surprised ASI didn't fix the problem, I'll have to look at the rules for insertion again.−dsschnau12yDoes it return that because `say` isn't defined inside its own function definition, so it evaluates as false?−TophWells12yIt doesn't seem to do anything.−rainmaking12yHahaha, nice!I'm getting a linter.−dismal212ythis is idiotic
Comments
This is why you should always use semicolons in JavaScript. Omitting semicolons here turns this:
into this:Most web browsers (if you're running this code in a web browser), will do ASI (automatic semicolon insertion).
http://jsfiddle.net/CxUXh/ works fine in Chrome, changing the console.log to an alert.
Not that I'm advocating omitting semicolons!
Interesting - your jsfiddle exhibits broken behaviour (alerting 'garrr') on my browser - chrome 33.0.1750.152. I believe I'm fairly up to date.
You're correct, I thought that was expected behavior, my mistake. TBH though, I'm surprised ASI didn't fix the problem, I'll have to look at the rules for insertion again.
Does it return that because `say` isn't defined inside its own function definition, so it evaluates as false?
It doesn't seem to do anything.
Hahaha, nice!
I'm getting a linter.
this is idiotic