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 trial

JavaScript JavaScript Basics (Retired) Storing and Tracking Information with Variables The Variable Challenge

Javier Mateo
Javier Mateo
2,624 Points

How can I add a space between variables when creating a concatenation?

Need a little help.

4 Answers

Grace Kelly
Grace Kelly
33,990 Points

Hi 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!!

var variable1 = "Hello";
var variable2="World";

var string = variable1 + " " + variable2;
//or
var string = variable1.concat( " ", variable2); 

//"Hello World''

Concatonate a set of quotes with a space in the quote.

var firstName = "samarth"; var lastName = "paboowal";

console.log(firstName + " " + lastName);