Essential JavaScript

Concatenation

JavaScript can add strings together. This is called concatenation.

To concatenate strings, we use the addition operator (+).

Try this: 'abra' + 'cadabra'

The result is a single string made of the two input strings. We can concatenate any number of strings this way.

Spaces

Try this: 'a' + 'healthy' + 'dessert'

Notice how the output doesn't have any spaces? If we want spaces in our string, we have to add them ourselves.

To put a space in a string, just make sure there is a space character inside the quotation marks.

Try this: 'a ' + 'healthy ' + 'dessert'

By including spaces in our original strings, we can have spaces in our result string. We can also add spaces by themselves.

Try this: 'a' + ' ' + 'healthy' + ' ' + 'dessert'


Learning Goals

Code Editor