JavaScript String Data Type
2025-01-08
let codeString = "perl";
let stackString = "LAMP uses ${codeString}";
let newString = `
This string spans
more than one line`; // Backticks
let anotherString = "A line that \
spans two lines"; // Backslash
let recommendedMethod = "Use the concatenatiion" +
'operator which has wider browser support";
let a = 'hello,';
let b = ' there';
a + b; 'hello, there'
const stringA = "Circle";
let stringLen = stringA.length; // 6
string0 = "This is a single quote: \'";
string1 = "This is a double quote: \"";
string2 = "This is a backslash: \\";
let result = targetString.substring(startIndex , endIndex);
let phoneNumberA = "1-800-555-5555"; // 14 chars
let phoneNumberB = "555-123-5555"; // 12 digits
let lenA = phoneNumberA.length;
let lastFourDigits = phoneNumberA.substring(lenA - 4, lenA);
let actionWord = actionWord.toUpperCase() + "!";
let targetString = "0123456789";
let digitIndex = targetString.indexOf('5'); // 5
let newString = originalString.replace("gray", "grey");
let newString = originalString.replace("colour", "color");
let noBookendWhiteSpaceString = messyString.trim();
let charAtIndex = targetString[10];
Return "\"" + charAtIndex + "\" is the tenth char.";
let firstString = "IDK";
let secondString = "IDK";
Return secondString.localeCompare(firstString); // 0 or IDK
let stringObject = new String("Cello");
Â