admin管理员组文章数量:1421542
Sorry if this question is to basic but how do I put a space in-between my two strings using JavaScript ?
The code in question is the following
console.log ("myFirstString + mySecondString = " + (myFirstString + mySecondString));
The out put is ing out as "myFirstString + mySecondString = MikeSlett"
I need there to be a space between Mike and Slett soo it reads " Mike Slett".
Thanks for any help!
Sorry if this question is to basic but how do I put a space in-between my two strings using JavaScript ?
The code in question is the following
console.log ("myFirstString + mySecondString = " + (myFirstString + mySecondString));
The out put is ing out as "myFirstString + mySecondString = MikeSlett"
I need there to be a space between Mike and Slett soo it reads " Mike Slett".
Thanks for any help!
Share Improve this question asked Jul 13, 2021 at 20:34 PoisonMasterPoisonMaster 471 silver badge6 bronze badges 2-
Well, how did you put the space between
=
andMikeSlett
? Any particular reason why you think string concatenation wont work on other places as well? – derpirscher Commented Jul 13, 2021 at 20:41 - Just needed the "" instead of one " so now I understand :) – PoisonMaster Commented Jul 13, 2021 at 20:48
3 Answers
Reset to default 3myFirstString + " " + mySecondString
In modern JavaScript you can use a template literal. Then just put a space between the variable substitutions.
console.log(`myFirstString + mySecondString = ${myFirstString} ${mySecondString}`)
[stringA, stringB].join(' ');
runs a bit faster than,
stringA + ' ' + stringB;
本文标签: javascriptHow do i put a space between my two stringsStack Overflow
版权声明:本文标题:javascript - How do i put a space between my two strings? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745347730a2654575.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论