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;
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745347730a4623640.html
评论列表(0条)