how to append character to string in javascript code example

Example 1: how to add a letter to a string javascript

String.prototype.splice = function(idx, rem, str) {
    return this.slice(0, idx) + str + this.slice(idx + Math.abs(rem));
};

var result = "foo baz".splice(4, 0, "bar ");
document.body.innerHTML = result; // "foo bar baz"

Example 2: js concatenate strings

const str1 = 'Hello';
const str2 = 'World';

console.log(str1 + str2);
>> HelloWorld

console.log(str1 + ' ' + str2);
>> Hello World

Example 3: javascript add to string

var s = 'hell'
s = s + 'o'