michael
michael

Reputation: 141

why chrome console not show "\n" as string but console.log output as normal line break?

Chrome Version: 90.0.4430.212

type "1\n2" then type "enter" showing "\n" string

type "console.log('1\n2')" then type "enter" showing normal

enter image description here

Upvotes: 12

Views: 3460

Answers (1)

JAC
JAC

Reputation: 295

The console reads the \n as new lines and outputs it the way it would look with the line breaks.

If you want to see the \n in console use JSON.stringify().

Example:

 

console.log('1\n2');
console.log(JSON.stringify('1\n2'));

Upvotes: 2

Related Questions