Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single or Double quotes in jQuery [duplicate]

Possible Duplicate:
When to Use Double or Single Quotes in JavaScript

This is specifically for jQuery not JavaScript in general since I'm not a JavaScript programmer and I'm starting to learn jQuery.

With the release of jQuery 1.6 was there a specific change on using single or double quotes?

For example, would the following function work in jQuery 1.6?:

$('.selector').show(); 

Or do I have to use double quotes?:

$(".selector").show(); 

Thanks in advance for any clarification.

like image 727
Ricardo Zea Avatar asked Aug 11 '11 14:08

Ricardo Zea


People also ask

What is the difference between single quote and double quote in jquery?

There is really no difference in the end between using single or double quotes, meaning they both represent a string in the end. The system doesn't really care which one you use (but you might?). No need to escape the other character within a string.

Is it better to use single quotes or double quotes in JavaScript?

In JavaScript, single (' ') and double (“ ”) quotes are frequently used for creating a string literal. Generally, there is no difference between using double or single quotes, as both of them represent a string in the end.

When assigning text to strings you can use single or double quotes?

use double quotes for strings and single quotes for chars. I prefer to use the same quoting across the board and so stick with double quotes for JS.


2 Answers

JQuery Core Style Guidelines says:

"Strings should always use double-quotes instead of single-quotes."

like image 102
Frink Avatar answered Sep 23 '22 00:09

Frink


You are allowed to use both. In JavaScript there is no difference between both (while e.g. in PHP there is a difference).

By the way, this is a JavaScript question. You are passing a string to the $() function, and strings have to be surrounded by ' or ".

like image 42
js-coder Avatar answered Sep 20 '22 00:09

js-coder