Math with strings?
+ operator. In this article, we aim to clear up some misconceptions you might have about doing math-like operations with strings.
This example shows the use of the
+ operator to connect multiple strings.
let firstName = "Freddy" let lastName = "Williams" let fullName = firstName + " " + lastName
+ operator without numbers on either side, it instead concatenates one string onto the end of the other.
NaN, which is short for Not a Number. NaN is the value given when arithmetic operators are used in a way that does not actually yield a number
let fullName = "Riley Davidson" let lastName = "Davidson" let firstName = fullName - lastName console.log(firstName) // this will log NaN, because only addition is supported for strings
Test your understanding by answering the question below.