Strings

A string is a sequence of characters.

It can be a word like "Hello", a number like "42", or an entire book. Strings are enclosed in quotation marks - either " or ', as long as it is consistent.

Loading TypeScript...

Every string has a set of known actions it can perform on its own characters. The simplest of these actions, like converting to upper/lower case, do not require any input.

Convert to upper case
"hello".toUpperCase()

Notice the similarity and differences between this function call and console.log above. Even though the function does not expect any input, we must still include an open and close parentheses (()) after the function name to call it.

Loading TypeScript...

To create a string that contains multiple lines of text, use the backtick ` operator.

Loading TypeScript...

You can join strings to other values with the + operator.

Loading TypeScript...

It is often important to include spaces within a string when concatenating them (i.e. joining them in order). When console.log receives multiple inputs, it will display them with a single space separator.

Loading TypeScript...

When using an operator like +, your computer follows standard left-to-right order of operations to produce the result, so you may also want to use parentheses (( and )).

Loading TypeScript...

Was this page helpful?