Title Case a Sentence Solution 3

Can someone explain to me why this solution works. “L” is never defined. At what point is it understood that L == first letter?

      function titleCase(str) {
  return str.toLowerCase().replace(/(^|\s)\S/g, L => L.toUpperCase());

function titleCase(str) {
return str.toLowerCase().replace(/(^|\s)\S/g, word => word.toUpperCase());

console.log (titleCase("I'm a little tea pot"));
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36.

Challenge: Title Case a Sentence

Link to the challenge:

L is the parameter to the callback “replacement” function which .replace accepts as the second argument.

You can check the MDN docs for examples of how it works.


1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.