The Quest for Quote Consistency


Ratkey

Double quotes or single quotes? That is the question.

After running down a problem with JSON being passed in a hidden field of HTML begin generated by PHP, I’ve come to a new (to me) coding rule for which type of quote to start out using:

  • Double quotes by default for server code (e.g. PHP) and data exchange (e.g. JSON).
  • Single quotes by default for client code (e.g. HTML and JavaScript for web, C and Java for apps).
  • Escape with a backslash (\”) as needed.

Example: echo “<table id=’users’><tr><td>”;

More discussion at http://stackoverflow.com/questions/242813/when-to-use-double-or-single-quotes-in-javascript

Whether ’tis nobler in the mind to suffer the bugs and hacks of inconsistent coding, or to take arms against a sea of quotation marks, and by standardizing, end them in confusion? Bill S.

View original post

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s