5.
What is the output of the following code?
let str = " Hello World ";
console.log(str.trim());
"Hello World "
" Hello World"
" Hello World "
"Hello World"
Correct: D
The trim() method removes whitespace from both ends of a string. Therefore, calling trim() on the string
" Hello World "
will remove the leading and trailing whitespace, resulting in the output "Hello World".