Coding for All
Lesson 5: Joining Strings
Joining Strings Glue two pieces of text together with +.
1const first = "Coding";
2const second = "is fun";
3console.log(first + " " + second);
Terminal
$ node main.js
Coding is fun
Every line, explained
const first = "Coding";
const creates a variable: a named box that stores a value. const is short for "constant": once a value is stored, that name can never be given a new value. Modern JavaScript uses const for most things. The semicolon ; marks the end of the statement.
const second = "is fun";
const creates a variable: a named box that stores a value. const is short for "constant": once a value is stored, that name can never be given a new value. Modern JavaScript uses const for most things. The semicolon ; marks the end of the statement.
console.log(first + " " + second);
Using + between strings glues them together; this is called concatenation. + adds no space by itself, so we glue a " " (a space) in the middle. Without it you would get Codingis fun.