Hi Friends 👋,
Welcome To Infinitbility! ❤️
To add a character to the beginning of a string in javascript, use the +
concatenate opertor and put your string before "+"
like this yourstring + string
, it will add character to the beginning of a string.
Today, I’m going to show you How do I add a character to the beginning of a string in javascript, as mentioned above, I’m going to create a sample string variable with data and use the +
concatenate opertor to add character at the beginning of a string.
Let’s start today’s tutorial on how do you add a character to the beginning of a string in javascript.
Javascript add a character to the beginning of a string
Here, we will do
- Create sample string variable
- Add character before string
// Create sample string variable
let str = "nfinitbility";
// Add character before string
str = "I" + str;
console.log(str)
// Infinitbility
// Better option
let str1 = "GuideHub";
str1 = `a${str1}`
console.log(str1)
// aGuideHub
Output
Output:
Infinitbility
aGuideHub
I hope it helps you, All the best 👍.