Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between “ " quotes in javascript?

Tags:

javascript

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

“ --> this gives an error

However,

" --> this does not

like image 774
Varun Grover Avatar asked Jul 09 '26 18:07

Varun Grover


1 Answers

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.

like image 144
ssube Avatar answered Jul 11 '26 07:07

ssube



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!