Javascript:如何打印字符串的原始内容(包括回车符)?

son*_*nrh 4 javascript string

例如,如果我有一个变量:

const template = `line 1
line 2
line 3`;
Run Code Online (Sandbox Code Playgroud)

我想console.log(template)打印:

第 1 行\n第 2 行\n第 3 行

epa*_*llo 6

只需将其字符串化即可

const template = `line 1
line 2
line 3`;

console.log(JSON.stringify(template))
Run Code Online (Sandbox Code Playgroud)