js remove spaces from beginning of string code example

Example 1: javascript trim spaces

value = value.trim();

Example 2: javascript remove spaces at the beginning of the end of the string

const stringWithSpaces = '   I learn JS with Coderslang every day   ';

console.log(stringWithSpaces.trimStart());  //'I learn JS with Coderslang every day   '
console.log(stringWithSpaces.trimEnd());    //'   I learn JS with Coderslang every day'
console.log(stringWithSpaces.trim());       //'I learn JS with Coderslang every day'

Example 3: suppress spaces in front and in the end of a string javascript

var hello = '     Hello there!    ';

// returns "Hello there!"
hello.trim();