To append a character to the beginning of a string in JavaScript, you can use string concatenation or template literals.
In this example,
str1
with a value of "ello"
.'H'
to str1
.str1
.let str1 = "ello";
str1 = 'H' + str1;
console.log(str1);
Hello
In this example,
str2
with a value of "orld"
.'W'
to str2
.str2
.let str2 = "orld";
str2 = `W${str2}`;
console.log(str2);
World
In this tutorial, we learned How to Append a Character to beginning of a String in JavaScript language with well detailed examples.