Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

87
Views
Display \n and \r\n characters in Dev Tools of a browser

In JavaScript, I have strings including newlines such as var s = "123\n456" or var s = "123\r\n456".

Using console.log(s), the dev tools of a browser displays real newlines in console.

I would like to know how to print literally the string. For instance, I want to see 123\n456 or 123\r\n456 in dev tools or a browser.

Could anyone help?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

you could console.log(JSON.stringify(s))

about 4 years ago · Juan Pablo Isaza Report

0

You can easily display the raw string using String.raw and a template literal

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw

const rawString = String.raw`Hello\nHow do you do?`;
console.log(rawString);

If you can not directly use a template literal, you can convert the string into a template literal, and then proceed. Note my linked method includes eval which can be a security risk depending on use.

i.e.

const myString = "Hello\nWorld";
const myRawString = eval("String.raw`"+myString+"`");
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!