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.