Why is it advisable not to use double quotes unless we are writing JSON in Node.js style?
The most likely reason is programmer preference / API consistency.
Strictly speaking, there is no difference in meaning; so the choice is convenient.
There are several factors that can influence your choice:
- Home Style: Some development teams are already using one convention or another.
- Client requirements: will you use quotes in strings? (See Ady's answer).
- Server side language: VB.Net people can use single quotes for java-script so that scripts can be built server-side (VB.Net uses double quotes for strings, so java-script strings are easily distinguishable if they use single quotes ).
- Library code. If you are using a library that uses a specific style, you can use the same style yourself.
- Personal preference: you can distinguish one style or the other.
Please check the following post you might find useful When to use JavaScript or JavaScript in two or two comments
First of all, this is just a style guide.
You can define your strings ECMAScript
however you like. It is syntactically correct to use single quotes or double quotes for strings.
But according to JSON Specifications
, the value JSON
can be a double-quoted string or a number, or true or false or null, or an object or an array.
source to share