Introduction

Let’s have a brief introduction to Strings in JavaScript.

String recap

Let’s recapitulate what we already know about strings:

  • A string value represents text.
  • In JavaScript, a string is defined by placing text within single quotes ('I am a string') or double quotes ("I am a string").
  • You may use special characters within a string by prefacing them with \ (“backslash”) followed by another character. For example, use \n to add a line break.
  • The + operator concatenates (combines or adds) two or more strings.

Beyond these basic uses, strings have even more versatility.

Obtaining string length

To obtain the length of a string (the number of characters it contains), add .length to it. The length will be returned as an integer.

Get hands-on with 1400+ tech skills courses.