Javascript line difference

Possible duplicates:
single quotes and double quotes in js
When to use JavaScript or JavaScript in two ways:

What is the difference (if any) between the javascript lines below?

var str1 = "Somestring";

var str2 = 'Somestring';

"and" means two very different things for me, mostly writing code in C ++ :-)

EDIT: If there is no difference why there are two ways to achieve the same thing, and what is considered best practice use and why. Thank!

+3
source share
4 answers

Javascript treats single and double quotes as line separators.

, , .

, , .

.

alert(str1 == str2); // true
alert(str1 === str2); // true

? - , javascript , html- :

var htmlString1 = "<a href='#'>link</a>";
var htmlString2 = '<a href="#">link</a>';

, . , .

, Javascript, , HTML ( , JS ', ").

+13

Javascript Unicode, ( "" ). , , , .

JavaScript- JavaScript HTML-, HTML- JavaScript. JavaScript, HTML , . , JavaScript HTML JavaScript HTML.

+3

.

+2

, . .

Here will be used '

var mynewhtml = '<body class="myclass" ></body>';

or using

var mynewhtml = "<body class='myclass' ></body>";

this works too, but IMO is harder to read

var mynewhtml = "<body class=\"myclass\" ></body>";
+2
source

Source: https://habr.com/ru/post/1747390/


All Articles