What is the difference between double quotation marks and single quotes in Javascript?


In PHP, there is a difference between the use of single and double quotes. In this case, single quotes are for "% common%", and double quotes, used when you want to process strings (concatenate, for example).

Is there any difference between using " and ' for string in Javascript? Is there any change in performance, or conflicts with strings , for example? >


alert('foo'); // Aspas simples
alert("bar"); // Aspas duplas
asked by anonymous 01.02.2014 / 20:47

3 answers


There are no differences from the programming point of view, even using Strict Mode ( "use strict;" )

As pointed out by Carlos André, one approach is to be able to put single quotation marks inside the string or the opposite:

alert('Ola "Mundo"');
alert("Ola 'Mundo'");

However, if you are using JSON, strings in JSON use double quotes. Of course, multiple libraries also support single quotes, but using single strings does not conform to JSON standards . / p>     

01.02.2014 / 21:11

There is no difference.

The only advantage of using double quotation marks is that you can put single quotation marks inside the string or the opposite:

var str = "Lorem 'ipsum' dolor";
var str = 'Lorem "ipsum" dolor'; 
01.02.2014 / 21:05

Although there is no rule when using both types of quotes, the most common is atributo herdar aspas duplas (") and argumentos do mesmo aspas únicas (') , if you want it possible to use the same type of quotes, without generating something error, just follow the template below.

\'conteudo\' or \"conteudo\" this way '\'a\'' will return in a function as 'a' , without error, containing the same type of quotation marks the attribute and its parameters. use strict is not affected by this type of use.


var teste = { a: function(a){ console.log(a.name); } }
19.10.2015 / 16:53