PoisonMaster
PoisonMaster

Reputation: 47

How do i put a space between my two strings?

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

Answers (3)

Nikki Winwood
Nikki Winwood

Reputation: 1

[stringA, stringB].join(' ');

runs a bit faster than,

stringA + ' ' + stringB;

Upvotes: 0

user16410343
user16410343

Reputation:

myFirstString + " " + mySecondString

Upvotes: 3

Barmar
Barmar

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

Related Questions