JavaScript Basics
Strings
Strings hold text. You can use single quotes, double quotes or backticks.
const first = "Sara";
const last = 'Khan';
const full = first + " " + last; // joining with +Template literals
Backticks let you put variables straight into a string with ${...} and write over several lines.
const course = "JavaScript";
const lessons = 13;
console.log(`${course} has ${lessons} lessons.`);Output
JavaScript has 13 lessons.
Useful string methods
const text = " Learn JavaScript ";
text.length; // 20
text.trim(); // "Learn JavaScript"
text.toUpperCase(); // " LEARN JAVASCRIPT "
text.includes("Java"); // true
text.trim().split(" "); // ["Learn", "JavaScript"]
text.replace("Learn", "Master");
"hello".at(-1); // "o"
"abc".slice(0, 2); // "ab"