var stringvar = ‘Hello from gyanipandit’; // you can also use the double quotes here.
You can try doing console.log(stringvar), and you get the string onto the console.
If you try to run the above program, into the console, the string ‘Welcome to GyaniPandit’ is going to be the output.
As you can see in the output, the string is there. You can also use the double quotes there. Also, we can make use of the backticks (these are found just above the tab key, or below the escape key) here. Let’s try this once as well.
As you know already, we can make use of single or double quotes for the strings. This means that if we are using the single quotes, we can simply say that the string is going to be surrounded by the single quotes, and the same is in the case of double quotes(it would be surrounded by double quotes). But sometimes, we might encounter such situations, when we need to use the single or double quotes inside the string, which need to be the part of the string here. So, how we can do this? The answer is quite easy, and this involves either the use of an escape sequence or using the appropriate quotes for the strings.
If you want to use quotes inside a string, then you can either use the escape characters, or there is one more technique to wrap the string with inappropriate quotes. What I mean is that if you want to use single quotes in a string, then wrap the string in double quotes. If you want to use double quotes in a string, then wrap that string into single quotes. Here are some examples for you to understand.
You can also access the characters of the string with the help of the index. If you try somestring in the above program, you will get the character present at the 5th index, which is the 6th element (since the index starts from zero). We can also use the charAt method for doing this thing(we are going to explore the charAt method ahead)