What does console.log('abc'.replace('b', "$`")) output?
A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-132.js
1console.log('abc'.replace('b',"$`"))
Coercion
Answer & explanation
Console output
aac
Why
The replacement pattern $` (dollar followed by a backtick) inserts the portion of the string that precedes the match. Here the match "b" is preceded by "a", so "b" is replaced with "a", yielding "aac". Its mirror image is $’, which inserts the text after the match.