Strings

Strings

  • Strings can consist of letters and other characters

  • They are surrounded by either double quotes or single quotes (this is how you recognize you are working with a string)

  • Concatenation allows you to combine strings

// declare a variable called color and store a string

const color = "green"

Single or double quotes can be used for strings, but the opening quote must match the closing quote


String Methods

  • JavaScript has some built-in methods that allow developers to work with strings

  • For example: if you wanted to know how many characters were in a string, you would use the .length method

  • Here are some example of other methods you can use on strings

JS Bin on jsbin.com

String Template Literals

  • Template literals were introduced with ES6 (the newest version of JavaScript)

  • Template literals provides are much cleaner syntax for mixing variables with strings

  • Template literals are enclosed by the back-tick (` `) character instead of double or single quotes

  • Template literals can contain placeholders. These are indicated by the dollar sign and curly braces (${expression})

  const name = "Tristan"

  console.log(`Hello ${name}`)

JS Bin on jsbin.com

Click here for complete list of all the String methods