Strings
Template Strings
- Interpolation, allows you to use variables or expressions inside of the string
const var1 = 123
const var2 = "David"
const msg =
`Hello ${var1}
${var2}`
Tagged Literals Templates
- Tagging a string allows you to execute a function before creating the string, pre processing
function functionCall(strings,...values){
}
const var1 = 12.34;
const msg = functionCall
`Message blah ${var1}`
- Tag functions allow you to format strings in many different ways.
- Can write regex inside tagged literals
Padding and Trimming
- Padding is adding characters
const str = "Hello"
str.padStart(5)
str.padStart(8)
str.padStart(8,"*")
str.padStart(8,"12345")
str.padStart(8,"ab")
- Trimming gets rid of whitespace
const str = " Hello David "
str.trim()
str.trimStart()
str.trimEnd()