Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJavier Mateo
2,624 PointsHow can I add a space between variables when creating a concatenation?
Need a little help.
4 Answers
Grace Kelly
33,990 PointsHi Javier you can add space in a couple of ways:
var name = "Mike";
var string = "Hello " + name + "!"; //space inside the string after Hello
or
var name = "Mike";
var string = "Hello" + " " + name + "!"; //place space in its own string
I personally prefer the first method, but everyone has their own preferences :)
Hope that helps!!
Dan Oswalt
23,438 Pointsvar variable1 = "Hello";
var variable2="World";
var string = variable1 + " " + variable2;
//or
var string = variable1.concat( " ", variable2);
//"Hello World''
Ted Sumner
Courses Plus Student 17,967 PointsConcatonate a set of quotes with a space in the quote.
samarth paboowal
Courses Plus Student 1,830 Pointsvar firstName = "samarth"; var lastName = "paboowal";
console.log(firstName + " " + lastName);