A string is a JavaScript primitive value representing text as a sequence of characters. Define strings with matching single or double quotation marks; mismatched quotes are invalid. JavaScript also supplies string properties and methods for inspecting, searching, changing, and splitting text. section 3.4.6
Use strings for these common tasks:
- Read text with length and charAt(index). section 3.4.6
- Combine values with concatenation or concat(string). section 3.4.6
- Search and transform text with indexOf, replace, slice, split, and related methods. section 3.4.6
- Insert values inline with template strings, using backticks and ${value} expressions. section 3.4.6
Literal strings and template output
let firstString = "This is a string"; let secondString = 'And so is this'; let place: string | undefined | null; console.log(`Place value: ${place} Type: ${typeof(place)}`); The template string produces: Place value: undefined Type: undefined. section 3.4.6
String coercion in JavaScript
function myFunction(param) { let result = param + 100; console.log("My result: " + result); } myFunction("London"); JavaScript converts 100 to a string, producing London100. A typeof check can reject unexpected values at runtime. section 3.4.2























