Search⌘ K
AI Features

Chars and Strings

Explore how JavaScript uses strings to represent letters, words, and text. Understand string literals, the use of single and double quotes, and how to escape characters and insert special whitespace like newlines and tabs. This lesson builds foundational knowledge for handling text in JavaScript programming.

In this chapter, we’ll be looking at how letters and words are represented and used in programming languages. We’ll also look at how JavaScript represents them using strings.

Introduction to chars and strings

As we saw in the previous chapter, most programming languages have primitive data types of char (a single character) and strings (a collection of characters). In fact, we can almost think of a string as a collection of characters joined together by a piece of string:

Chars on a string
Chars on a string

JavaScript only has a primitive data type ...