Skip to content

Files

Latest commit

 

History

History
21 lines (15 loc) · 616 Bytes

prefer-string-raw.md

File metadata and controls

21 lines (15 loc) · 616 Bytes

Pattern: Multiple escape characters in string

Issue: -

Description

Using String.raw allows you to write paths and regular expressions without escaping backslashes, making the code more readable. This is particularly useful for Windows paths and regular expressions that contain many backslashes.

Examples

Example of incorrect code:

const file = "C:\\windows\\style\\path\\to\\file.js";
const regexp = new RegExp("foo\\.bar");

Example of correct code:

const file = String.raw`C:\windows\style\path\to\file.js`;
const regexp = new RegExp(String.raw`foo\.bar`);