What is difference between single and double quotes? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

What is difference between single and double quotes?

i am new to java script and dont understand what are double wuotes for, could someone explain this to me?

3rd Jul 2017, 12:24 PM
Maciek Pięta
Maciek Pięta - avatar
5 Answers
+ 7
Simple and double quotes works same in JS... the only obvious difference is that to handle them inside themselve you must escape them: alert("He said \"I love potatoes\" "); // OK alert('I\'m a little bird'); //OK Rest is question of tastes... I personnaly keep the habits to use simple quotes, so I can easily embed Html code in strings, with the habit to use double quotes for Html code ^^
3rd Jul 2017, 12:50 PM
visph
visph - avatar
+ 1
You can include single quotes in double quotes : alert('Hey!');//OK alert('He said "I love potatoes" ');//error alert("I'm a little bird");//OK If you don't understand ask !
3rd Jul 2017, 12:28 PM
Jojo
+ 1
cant i just write normal quote sign, or it wont work so i must use double quote?
3rd Jul 2017, 12:30 PM
Maciek Pięta
Maciek Pięta - avatar
+ 1
Ok, now i understand it bettwr ^^ Thanks for explaining <3
3rd Jul 2017, 12:33 PM
Maciek Pięta
Maciek Pięta - avatar
0
You can use simple quotes but if one day you have to write a sentence with an apostrophee, it won't work.
3rd Jul 2017, 12:32 PM
Jojo