Today I Learned

String.raw()

After running into a problem of wanting to console.log() a string that had a backslash in it - which are usually used to escape the next character rather than being treated as a character themselves - I stumbled upon String.raw(); a template literal (string with backticks) function.

You need to pass it a template literal, and it'll spit out the processed string - except that it won't escape characters, it'll come out raw.

Here's an example:

console.log('Look, a down arrow: \/');
// Prints: Look, a down arrow: /   <-- Notice the missing part?

console.log(String.raw`Look, a _working_ down arrow: \/`);
// Prints: Look, a _working_ down arrow: \/

Read more: MDN String.raw()


Back to TIL

Let's grow your business,
together

Whether you're after dev work on a brand new site, an updated design, or just have a great business idea you want to get the ball rolling on, I'm here to help. Let's collaborate together!

Start a project