function trimStr(str){return str.replace(/(^\s*)|(\s*$)/g,""); } a = ' runoob ' console.log(trimStr(a));