gpt4 book ai didi

JavaScript : White space adding between two string vriable why not in sequence of two strings

转载 作者:行者123 更新时间:2023-12-03 06:11:29 26 4
gpt4 key购买 nike

1)使用变量:

var str1 = "Hi";

var str2 = "Geeks!";

document.write(str1+str2);

输出:

嗨,极客们!

<小时/>

2) 使用引号

document.write("Hi"+"Geeks!");

输出

嗨极客!

<小时/>

但是,在由字符串组成的序列中,如果我使用引号,则两个字符串的连接之间没有任何空格。为什么?谢谢。

最佳答案

你是说在下面的代码中(1)打印

Hi Geeks!

和(2)

HiGeeks!

前者有空格,后者没有空格? jsfiddle

<head>
<script src="script.js"></script>
</head>

<body>
<script>
var str1 = "Hi";
var str2 = "Geeks!";

document.write(str1 + str2); //(1)
document.write("<br>");
document.write("Hi" + "Geeks!"); //(2)

</script>
</body>

</html>

如果你这样写,它们之间没有空格:

document.write("Hi" + " Geeks!");

或者这个:

document.write("Hi " + "Geeks!");

或者这个:

document.write("Hi" + " " + "Geeks!");

有一个!

关于JavaScript : White space adding between two string vriable why not in sequence of two strings,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39297233/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com