+ 1

Hey, guys. Can you explain to me what this line means. Especially the 0, the dollar sign and sign =>

"font-size".replace(/-\w/g, $0 => $0.toUpperCase());

10th May 2021, 9:18 PM
Тимур Завьялов
Тимур Завьялов - avatar
2 Respuestas
+ 3
It 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.
11th May 2021, 6:01 PM
Josh Greig
Josh Greig - avatar
0
Josh, thank you
11th May 2021, 7:32 PM
Тимур Завьялов
Тимур Завьялов - avatar