How to uppercase every word in JavaScript

Strings
By Jad Joubran · 
Last updated Dec 26, 2018
let string = "code to go is AWESOME";
const pattern = /([^\W_]+[^\s]*) */g;

string.replace(pattern, word => {
  const first = word[0].toUpperCase();
  const rest = word.substring(1).toLowerCase();
  return first + rest;
});
Code To Go Is Awesome