Code Monkey home page Code Monkey logo

Comments (7)

hshoff avatar hshoff commented on May 5, 2024 12

This a preference. The important thing, as @jaseemabid points out is consistency. At Airbnb we use '' which is what is reflected in the style guide.

Feel free to fork the style guide and make one that prefers "" over '' for you and your team.

from javascript.

ljharb avatar ljharb commented on May 5, 2024 3

The eslint rule allows for double quotes when it would avoid escaping backslashes.

However, since both straight quotes are typographically incorrect - you should be using curly quotes in prose - this is only a problem when working with strings of html, which double-quotes it’s attributes. Thus, it’s basically never a problem with correct code/text.

from javascript.

jaseemabid avatar jaseemabid commented on May 5, 2024 2

@GurudayalKhalsa I would say pick any and be consistent.

Generally its a convention to use " in html and if you have inline html in your js (we all have some, don't we? ) its easier to quote it all with a single ', without a lot of \

from javascript.

nkbt avatar nkbt commented on May 5, 2024 2

@GurudayalKhalsa, single-quoted strings look better for me

  1. " === + '. Easier to type =)
  2. In PHP single-quoted strings are just plain strings, double-quoted strings allow to put variables inside and therefore work a bit slower. So it is just a habit to use single-quotes.

from javascript.

jaseemabid avatar jaseemabid commented on May 5, 2024 1

Just to add up, straight from coffeescript docs.

String Interpolation, Block Strings, and Block Comments

Ruby-style string interpolation is included in CoffeeScript. Double-quoted strings allow for interpolated values, using #{ ... }, and single-quoted strings are literal.

Single and double quoted strings behave exactly the same way in JS, but I got used to the coffee way and now its natural to write it that way..

from javascript.

theage avatar theage commented on May 5, 2024

One could use single-quote strings only if there are double quotes in the string, and use double-quote strings otherwise. It would still be consistent, though the rule maybe less obvious, and you lose an excuse for not double-quoting strings in many cases.

from javascript.

Come2Daddy avatar Come2Daddy commented on May 5, 2024

I just find that backticks are closer to single quotes than double quote and IMHO can sometime cause readability issues.
HTML fits (today) well in a backticks bloc as it allows for a clean multiline implementation without any collision with most common quote style (single and double).

from javascript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.