Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single quote or double quote in javascript

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 ?

like image 782
Tinple Avatar asked Jul 12 '13 06:07

Tinple


1 Answers

: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 `""`
like image 140
bipen Avatar answered Sep 30 '22 05:09

bipen