HTML CSS JavaScript SEO Python Posts Privacy About Contact

JS Strings

JavaScript strings are for storing and manipulating text.

JavaScript strings are used for storing and manipulating text. A JavaScript string is simply zero or more characters written inside quotes.

String Length

To find the length of a string, use the built-in length property.

Preview

Escape Character

Because strings must be written within quotes, JavaScript will misunderstand this string:

let text = "We are the so-called "Vikings" from the north.";

The string will be chopped to “We are the so-called ”. The solution to avoid this problem, is to use the backslash escape character. The backslash (\\) escape character turns special characters into string characters.

Preview

String Methods overview

String methods help you to work with strings:

  • String length
  • String slice()
  • String substring()
  • String replace()
  • String toUpperCase()
  • String toLowerCase()
  • String concat()
Preview

JavaScript Template Literals

Template Literals use back-ticks (`) rather than the quotes (") to define a string. Template literals allow variables in strings without using concatenation operators (+).

Preview