Skip to content

Instantly share code, notes, and snippets.

@deden
Last active November 28, 2017 07:36
Show Gist options
  • Save deden/d5482b576a5305d31fade6cc7a61bb75 to your computer and use it in GitHub Desktop.
Save deden/d5482b576a5305d31fade6cc7a61bb75 to your computer and use it in GitHub Desktop.
// returns: undefined
// explanation: an empty block with an implicit return
((name) => {})()
// returns: 'Hi Jess'
// explanation: no block means implicit return
((name) => 'Hi ' + name)('Jess')
// returns: undefined
// explanation: explicit return required inside block, but is missing.
((name) => {'Hi ' + name})('Jess')
// returns: 'Hi Jess'
// explanation: explicit return in block exists
((name) => {return 'Hi ' + name})('Jess')
// returns: undefined
// explanation: a block containing a single label. No explicit return.
// more: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label
((name) => {id: name})('Jess')
// returns: {id: 'Jess'}
// explanation: implicit return of expression ( ) which evaluates to an object
((name) => ({id: name}))('Jess')
// returns: {id: 'Jess'}
// explanation: explicit return inside block returns object
((name) => {return {id: name}})('Jess')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment