Setting the stage for learning...
  1. Learn Langs
  2. Learn JS
  3. Strings

Strings

6 / 8

Provided by Learn Langs

Strings

Strings

In JavaScript, the textual data is stored as strings\. There is no separate type for a single character\.

The internal format for strings is always UTF\-16, it is not tied to the page encoding\.

  • - There are 3 types of quotes\. Backticks allow a string to span multiple lines and embed expressions $\{…\}\. - We can use special characters, such as a line break \\n\. - To get a character, use: \[\] or at method\. - To get a substring, use: slice or substring\. - To lowercase/uppercase a string, use: toLowerCase/toUpperCase\. - To look for a substring, use: indexOf, or includes/startsWith/endsWith for simple checks\. - To compare strings according to the language, use: localeCompare, otherwise they are compared by character codes\.
  • There are several other helpful methods in strings:
  • - str\.trim\(\) – removes \(“trims”\) spaces from the beginning and end of the string\. - str\.repeat\(n\) – repeats the string n times\. - …and more to be found in the manual\.
  • Summary

    Video
    ← Numbers Class basic syntax →