console.log(`Hello\nworld`);
//Hello
// world
console.log(String.raw`Hello\nworld`);//Hello\nworld
// String.raw函数是用来获取一个模板字符串的原始字符串的,它返回一个字符串,其中忽略了转义符(\n,\v,\t等)
//但反斜杠可能造成问题,会被去掉
const path = `C:\Documents\Projects\list.html`
console.log(String.raw`${path}`);//C:DocumentsProjectslist.html
console.log(String.raw`C:\Documents\Projects\list.html`);//C:\Documents\Projects\list.html
js中String.raw 将模板字符串不转义的原始字符串内容返回
于 2023-07-20 15:03:24 首次发布