Hey, guys. Can you explain to me what this line means. Especially the 0, the dollar sign and sign =>
2 Answers
New Answer"font-size".replace(/-\w/g, $0 => $0.toUpperCase());
5/10/2021 9:18:40 PM
Тимур Завьялов2 Answers
New AnswerIt means capitalize letters immediately following a minus/hyphen sign. This example makes the regular expression behaviour more clear: "font-size world -yo".replace(/-\w/g, $0 => $0.toUpperCase()); "font-Size world -Yo" Here is a more detailed look at your replace call: \w means word character. In other words the letters in [a-z]. For every occurrence of a - sign followed by a letter, convert to upper case. The "$0 => $0.toUpperCase()" is a function with no name expressed with the arrow syntax. $0 is the string that matched the regular expression pattern. $0 could be something like "-s". The $0 could be named whatever you want. "matchString" would have been more descriptive.
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message