Common string methods in JavaScript

Thursday, Jul 30, 2020
JavaScript
const greet = " hello ";
const lang = "javascript";

greet.length                    // 7, length is a property and not method
greet[1]                        // h, returns single character
greet.includes("ree")           // false
greet.substring(1, 3)           // he, first index included, second excluded
greet.substring(1)              // hello , 2nd argument optional
greet.trim() + lang             // hellojavascript
greet.startsWith("h")           // true
lang.endsWith("d")              // false
greet.toUpperCase()             // HELLO
"JS".toLowerCase()              // js

`${lang} is a cool language!`   // javascript is a cool language
`${greet}
${lang}`                        // backticks can be used for multiline strings

let num = 59;
num.toString(10);               // "59"
Number.parseInt("59", 10)       // 59, second argument, radix, is important

"truck-car".split("-")          // ["truck", "car"]