0

Possible Duplicate:
When to Use Double or Single Quotes in JavaScript
Difference between single quotes and double quotes in Javascript

When I started learning jQuery, I frequently found examples using single quote or double quote as jQuery selector:

$('#myDiv'); or $("#myDiv");

They are basically the same. But which one is used prefer and fast execute please let me know.

Community
  • 1
  • 1
Narendra Patel
  • 307
  • 2
  • 12

4 Answers4

6

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, performance vise also both are same.

Jainendra
  • 24,713
  • 30
  • 122
  • 169
3

There's no performance difference. They mean the same thing. I usually use singles for property names and other short literals, and doubles for long text that the user will see. The exception of course, is when one of the two appears inside the string, then use the other.

David Kanarek
  • 12,611
  • 5
  • 45
  • 62
0

Personally I use double quotes when working with strings (= more than one char) and single quotes when working with chars (= one char) although there is no difference in Javascript. There's also no "hidden" feature in double quotes like there is in php.

Community
  • 1
  • 1
0

jQuery code style mandates the use of double-quotes, but there's no diference in usage.

Double quotes are typed faster =)

Soulbe
  • 444
  • 8
  • 14
  • 1
    Why are double-quotes faster to type? On my keyboard the single and double quote are on the same key, but double needs shift. Also, can you provide a reference for the jQuery code style you mention? In their API reference they seem to use both types in equal numbers with no rhyme or reason... – nnnnnn Oct 26 '12 at 11:53
  • @nnnnnn: It's just a personal comment of usability!!Read this for a reference to what i've said http://docs.jquery.com/JQuery_Core_Style_Guidelines#Strings to – Soulbe Oct 26 '12 at 12:07