Does the type of quotes matter when using use strict?
Asked Answered
L

2

24

I was wondering since I'm trying to use use strict, does it matter if I go with "use strict" or 'use strict'?

Is any of those a «more correct» option?

Limousin answered 30/12, 2013 at 14:25 Comment(3)
no. To invoke strict mode for an entire script, put the exact statement "use strict"; (or 'use strict';) before any other statements.Underline
Just stick with the same quotation style you use in the rest of your code. All of your code should look like it was written by one person.Quartern
See also the ES5 spec on Use Strict Directives (which says the same things as the MDN page, above): ecma-international.org/ecma-262/5.1/#sec-14.1Acrid
B
24

Actually in Javascript using double quotes or single quotes doesn't change anything.

It's more important you use the same option in your entire code.

Even if you use mixed quotes it will not change anything:

'use strict'
var myString = "double quotes string"

So using use strict with double quotes or single quotes are the same.

In many libraries they commonly use one of them for strings and another to avoid escape, like in this example:

'A string that\'s single quoted'

"a string that's double quoted"

So specifically in English sometimes is useful using double quotes instead of single quotes to avoid this kind of escape thing.

Batt answered 30/12, 2013 at 15:8 Comment(2)
That's exactly what I needed to know. The type of quotes according to the language used matters a lot to me, so, thank you.Limousin
@Limousin In my case if I type single quotes I even avoit hit ShiftBatt
W
-4

No, in pretty much any code language, it does not matter whatsoever what type of quotes you use.

Wistrup answered 23/5, 2017 at 21:36 Comment(2)
Actually, in a number of languages - Perl and PHP come to mind - single and double quotes have different behaviors. See for example What is the difference between single-quoted and double-quoted strings in PHP?Electroplate
@PaulRoub Yes, there is a small difference depending on what language your currently using, but that doesn't mean that they can't experiment and figure out what's right or wrong. A waste of a post if you ask me.Wistrup

© 2022 - 2024 — McMap. All rights reserved.