String is a built-in JavaScript function and constructor that converts values to strings and can create String objects. In everyday code, string values represent text and can be written with single quotes, double quotes, or template strings. section 3.2 section 3.3.1
JavaScript assigns types to values rather than variables. A variable can therefore hold a string and later hold a number, while typeof reports the type of its current value. section 3.3.1 section 7.2
A string can change an operation
let hatPrice = 100; let bootsPrice = "100"; if (hatPrice == bootsPrice) { console.log("Prices are the same"); } let totalPrice = hatPrice + bootsPrice; console.log(`Total Price: ${totalPrice}`); // Prices are the same // Total Price: 100100 section 3.2
Inspecting the current value type
let myVar; console.log(`${myVar} = ${typeof myVar}`); myVar = 12; console.log(`${myVar} = ${typeof myVar}`); myVar = "Hello"; console.log(`${myVar} = ${typeof myVar}`); myVar = true; console.log(`${myVar} = ${typeof myVar}`); section 7.2
Listing 3.6 Adding statements in the index.ts file in the primer folder
let hatPrice = 100;
console.log(`Hat price: ${hatPrice}`);
let bootsPrice = "100";
console.log(`Boots price: ${bootsPrice}`);
if (hatPrice == bootsPrice) {
console.log("Prices are the same");
} else {
console.log("Prices are different");
}
let totalPrice = hatPrice + bootsPrice;
console.log(`Total Price: ${totalPrice}`);
Compare the numeric and string prices, then observe how the string changes addition from arithmetic into concatenation. section 3.2























