Standard built-ins

Symbol.replace

Try the free JavaScript compiler

Key for the replacement hook consulted by string replace and replaceAll; receives the string and replacement.

Formal Syntax & Structure

javascript syntaxjavascript
Symbol.replace

Return Value

symbol

The predefined protocol key.

Working Example

Example Snippetjavascript
const x={[Symbol.replace](s,r){return r+s;}};console.log("ab".replace(x,"!"));
JavaScript Reference