xxxxxxxxxx
\s is the regex character for whitespace. It matches spaces, new lines, carriage returns, and tabs.
xxxxxxxxxx
let str = " tushar is a good boy "
let repl = str.replace(/^\s+|\s+$|\s+(?=\s)/g, "");
// gives: "tushar is a good boy"