Skip to content

Instantly share code, notes, and snippets.

@rotimi-best
Last active November 15, 2019 15:06
Show Gist options
  • Save rotimi-best/5e12813c7d1f0a5a298993a59b07fc79 to your computer and use it in GitHub Desktop.
Save rotimi-best/5e12813c7d1f0a5a298993a59b07fc79 to your computer and use it in GitHub Desktop.
Basic simple to understand how to pass a default value for a required functional argument
const { log } = console;
const run = (a) => `${a} - Run`
const dance = b => `${b} - Dance`
const defaultAction = c => `${c} - Can do all things :)`
const human = (action = defaultAction) => action('A human can')
log(human()) // A human can - Can do all things :)
log(human(run)) // A human can - Run
log(human(dance)) // A human can - Dance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment