JavaScript: Object Literal over Switch Statement


2018-02-24 · 1 min read
function dispatchStatus(status) {
  const statuses = {
    'accepted': () => 'This is accepted',
    'rejected': () => 'This is rejected',
    'pending': () => 'This is pending',
    'default': () => 'Status unknown'
  };
  return (statuses[status] || statuses['default'])();
}

dispatchStatus('accepted')

My Tech Newsletter

Get emails from me about programming & web development. I usually send it once a month