Reputation: 141
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
Upvotes: 12
Views: 3460
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