Varun Grover
Varun Grover

Reputation: 37

What is the difference between “ " quotes in javascript?

I was wondering what is difference between these two quotes in javascript “ " as

“ --> this gives an error

However,

" --> this does not

Upvotes: 3

Views: 114

Answers (1)

ssube
ssube

Reputation: 48257

Per the specification, section 11.8.4:

A string literal is zero or more Unicode code points enclosed in single or double quotes...

Syntax

StringLiteral ::
    " DoubleStringCharactersopt "
    ' SingleStringCharactersopt '

JS string literals may use single or double quotes, but not smart quotes. They are not recognized as delimiters for a string literal, hence your error:

console.log("Look friends, “fake quotes”!");

With ES6+, template literals were introduced (s11.8.6), which use backticks (```) rather than quotes.

This is somewhat in contrast to JS' rules on variable names, which may use Unicode characters, although they are still not interchangeable.

Upvotes: 5

Related Questions