Essential JavaScript

Going Further

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

  • I know what concatenation is

  • I can concatenate strings

  • I can use spaces in strings

Code Editor

Click "Run Code" to execute your JavaScript in a secure sandbox and see the output below.

Console Output

// Console output will appear here...

0 output lines