const str = "codingCourses";

console.log(str.substring(0, 6)); // Output: "coding"
console.log(str.substring(6, 12)); // Output: "Course"
console.log(str.substring(6)); // Output: "Courses"

/* If the start index is greater than the end index,
   the function behaves as if the two indices were swapped. */
console.log(str.substring(12, 6)); // Output: "Course"

/* 👇 The original string remains unchanged. */
console.log(str); // Output: "codingCourses"
str.substring(indexStart);
str.substring(indexStart, indexEnd)
const str = "codingCourses";

console.log(str.substring(6, 0)); // Output: "coding"
// Equivalent to str.substring(0, 6)
const str = "codingCourses";

console.log(str.substring(3)); // Output: "ingCourses"
const str = "codingCourses";
const result = str.substring(3, 3);

console.log(result);        // Output: ""
console.log(typeof result); // Output: "string"
console.log(result.length); // Output: 0
const str = "codingCourses";

console.log(str.substring(-1, 3)); // Output: "cod"
console.log(str.substring(4, -3)); // Output: "codi"
const str = "codingCourses";

console.log(str.substring(0, 50));           // Output: "codingCourses"
console.log(str.substring(0, str.length));   // Output: "codingCourses"
const str = "codingCourses";
const indexStart = "coding" * 2;

console.log(indexStart);                   // Output: NaN
console.log(str.substring(indexStart, 3)); // Output: "cod"
const str = "JavaScript";

// substring(): Swaps 4 and 1, effectively becoming substring(1, 4)
console.log(str.substring(4, 1)); // Output: "ava"

// slice(): Does not swap indices; returns an empty string
console.log(str.slice(4, 1));     // Output: ""
const formatPhoneNumber = phoneNumber => {
    // Formats a 10-digit string into (XXX) XXX-XXXX
    return "(" + phoneNumber.substring(0, 3) + ") " +
           phoneNumber.substring(3, 6) + "-" +
           phoneNumber.substring(6);
}

console.log(formatPhoneNumber("1234567890")); // Output: "(123) 456-7890"
const formatDate = dateString => {
    const month = dateString.substring(0, 2);
    const day   = dateString.substring(3, 5);
    const year  = dateString.substring(6, 10);
    
    return `${month}/${day}/${year}`;
}

console.log(formatDate("02-27-2024")); // Output: "02/27/2024"
const emphasizeText = (text, startIndex, endIndex) => {
    return text.substring(0, startIndex) +
           "<strong>" + text.substring(startIndex, endIndex) +
           "</strong>" + text.substring(endIndex);
}

const originalText = "JavaScript is powerful!";
console.log(emphasizeText(originalText, 0, 10)); // Output: "<strong>JavaScript</strong> is powerful!"