var name = “John said ‘Hi there developers’ and waved”;
var name = ‘John said “Hi there developers” and waved’;
Both of the above variables are completely valid, but they are slightly different. The first variable stores your quote of ‘Hi there developers’ in single quotes, while the second stores it in double quotes. This is a point for consideration when declaring your variables. If you need to use double quotes on the inside, you must make sure you use single quotes on the outside. It is not possible to use both, however.
Moving on, let‘s imagine for a second that we wanted to store a string with the following text ‘John said “Hello, it’s great to meet you”’. How do you think you might do that?
Give it a go yourself and see if you can figure it out.
Did you work it out? Or did you run into an error message? The tricky part here is that we are trying to create a variable with a string that contains both a single and a double quote inside it, and that’s not possible to do at the same time. A solution to this problem that you might have come to is actually quite straightforward, but it does require some creative thinking (something that you will need to get used to if you want to be a programmer!). Let’s see the solution below: