为什么 chrome 控制台不将 "\n" 显示为字符串,而将 console.log 输出显示为正常的换行符?

问题描述

Chrome 版本:90.0.4430.212

输入 "1\n2" 然后输入 "enter" 显示 "\n" 字符串

输入“console.log('1\n2')”然后输入“enter”显示正常

enter image description here

解决方法

控制台将 \n 读取为新行,并以换行符的方式输出。

如果你想在控制台中看到 \n 使用 JSON.stringify()。

示例:

parameters.ReferencedAssemblies.AddRange(references);
CompilerResults compiledCode = compiler.CompileAssemblyFromSource(parameters,code);