Reputation: 47
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 coming 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!
Upvotes: 2
Views: 5261
Reputation: 1
[stringA, stringB].join(' ');
runs a bit faster than,
stringA + ' ' + stringB;
Upvotes: 0
Reputation: 780724
In modern JavaScript you can use a template literal. Then just put a space between the variable substitutions.
console.log(`myFirstString + mySecondString = ${myFirstString} ${mySecondString}`)
Upvotes: 1