当我创建模板文字时,我会使用trim() 来删除多余的空间。但我注意到,当我在 JS 函数中执行此操作时,它仍然会创建额外的制表符或空白。
function BottlesOfBeer() {
for (i = 99; i>=1; i--) {
if (i === 1) {
var oneBottle = "1 bottle of beer on the wall, 1 bottle of beer.\n" +
"Take one down and pass it around, no more bottles of beer on the wall.\n" +
"No more bottles of beer on the wall, no more bottles of beer.\n" +
"Go to the store and buy some more, 99 bottles of beer on the wall.";
console.log(oneBottle); …Run Code Online (Sandbox Code Playgroud)