What is the purpose of trim method

Tell us what’s happening:
Why do we need the trim function if there are no spaces at the beginning or end of the strings? I printed the function when the array has two spaces between words and it printed properly, but when I run the program, it doesn’t render properly.

Your code so far
var globalTitle = “Winter Is Coming”;

// Only change code below this line
function urlSlug(title) {
return title
.toLowerCase()
.split(/\s+/)
.join("-");
}


// The global variable
var globalTitle = "Winter Is Coming";

// Only change code below this line
function urlSlug(title) {
return title
.toLowerCase()
.trim()
.split(/\s+/)
.join("-");
}
// Only change code above this line

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36.

Challenge: Apply Functional Programming to Convert Strings to URL Slugs

Link to the challenge:

The trim() in js, is used to get rid of white spaces from both sides.
In simple terms, if you wanna get rid of white space that exists in front of the letter or after the letter.
Remember it won’t get rid of spaces in between the words.

Consider this:

const title = '  ';
const splitted = title.split(/\s+/); // ["", ""]
const kebab = splitted.join('-'); // "-"