JS Strings
On this page
JS Strings
Strings represent text in JavaScript. You can create them using single quotes, double quotes, or backticks.
let a = "Hello"; let b = 'World'; let c = `JavaScript`;
JS String Templates
Template literals use backticks (`) and allow embedded expressions using ${ }.
let name = "Ozan";
let message = `Hello, ${name}!`;
console.log(message);
Template literals also support multi-line strings.
let text = `Line one Line two Line three`; console.log(text);
JS String Methods
Strings have built-in methods to manipulate text.
let str = "JavaScript";
console.log(str.length); // 10
console.log(str.toUpperCase()); // JAVASCRIPT
console.log(str.toLowerCase()); // javascript
console.log(str.slice(0, 4)); // Java
console.log(str.replace("Java", "Type")); // TypeScript
Common methods include trim(), includes(), startsWith(), and endsWith().
let text2 = " Hello JS ";
console.log(text2.trim());
console.log(text2.includes("JS"));
console.log(text2.startsWith("He"));
JS String Search
You can search inside strings using different methods.
let phrase = "Learn JavaScript easily";
console.log(phrase.indexOf("Java")); // position
console.log(phrase.lastIndexOf("a")); // last match
console.log(phrase.search("Script")); // search
console.log(phrase.match(/Java/)); // RegExp match
JS String Reference
Strings are immutable, meaning methods return new strings instead of modifying the original value.
let original = "Hello"; let updated = original.toUpperCase(); console.log(original); // Hello console.log(updated); // HELLO
For a complete list of string methods, refer to the JavaScript reference documentation.
Next Step
Continue with JS Numbers to learn how JavaScript handles numeric values and calculations.