JavaScript default parameters

Published on September 2nd, 2019

javascript icon

Passing default parameters to JavaScript function is as easy as declaring them in function ‘head’ (I really can’t think of a better name for that).

const sayHi = (user = 'default user') => {
  return `Hey, ${user}!`

Now, if we don’t pass user parameter or it’s undefined, it will use default value.