Thursday, May 17, 2012

Difference between single quotes and double quotes in Javascript


I know that in PHP the only difference between double quotes and single quotes is the interpretation of variable inside a string.



Well, in jQuery Javascript, I often see doublequotes used in jQuery selectors, or in strings, is there a particular reason for that or is single quotes just the exact same as doublequotes?


Source: Tips4all

4 comments:

  1. You'll want to use single quotes where you want double quotes to appear inside the string (e.g. for html attributes) without having to escape them, or vice versa. Other than that, there is no difference.

    ReplyDelete
  2. There is a difference in JSON, so I have started switching to using double-quotes as much as possible so that I don't make mistakes when dealing with JSON.

    ReplyDelete
  3. Absolutly no difference. FREE QUOTING YEEHHAAA

    ReplyDelete
  4. They are the same, I usually use single quotes but thats because I am a .net developer and asp.net in particular so it aids me in distinguishing between the 2 types of strings.

    ReplyDelete