Single quote or double quote in javascript

javascript, jquery

Solution

:contains("topic")

this search for elements that contains "topic" string

where as

 var topic = "community";
 :contains(topic)

topic here becomes "community"..so it searchs for element that contains "community";

well for this

:contains("' + topic + '")

i guess the code is incomplete..

 $('div:contains("' + topic + '")')..; //div for example sake

this becomes

 $('div:contains("community")')..; //<-- just to make sure the string is encoded with `""`

Problem

I always see a write style in javascript but I don't know why code like this. For example, I have a variable. ``` var topic = "community"; ``` And when I learned javascript I saw someone coded in jQuery like this, some code in section. ``` :contains("' + topic + '") ``` But I think it can code just like this. ``` :contains(topic) ``` Or :contains("topic") What the differences between above three ?

Original source

Related problems