const originalString = "   Welcome! Nice to meet you!  ";
const trimString = originalString.trim();

/* Spaces inside the string are preserved.
   The original string is not modified; only a new string is returned. */
console.log(trimString); // Output: "Welcome! Nice to meet you!"

/* 👇 The original string remains unchanged. */
console.log(originalString); // Output: "   Welcome! Nice to meet you!  "
str.trim()
const number = 17;

try {
    let result = number.trim(); // TypeError occurs here
    console.log(result);
} catch (error) {
    console.error(error); // TypeError: number.trim is not a function
}
const str = "   Hello, World!   ";
const trimmedStr = str.replace(/^\s+|\s+$/g, "");

console.log(trimmedStr); // Output: "Hello, World!"