var string = "Javascript is fun"; var newString = string.replace(" ", "_"); console.log(newString); // Javascript_is_fun