Javascript-how to correctly use single quotes and double quotes during programming?

Source: Internet
Author: User
More and more open-source programs (PHP and Javascript) are using single quotes when processing strings. Why not use double quotation marks? What is the difference between the two? More and more open-source programs (PHP and Javascript) are using single quotes when processing strings. Why not use double quotation marks? What is the difference between the two?

Reply content:

More and more open-source programs (PHP and Javascript) are using single quotes when processing strings. Why not use double quotation marks? What is the difference between the two?

In php, variables ($ var) and special characters (\ r \ n) in double quotes are escaped, and the content in single quotes is not escaped (so it is more efficient ).
In use, I used to like to write $ SQL = "SELECT * FROM table WHERE id = $ id" in the SQL string, so that the $ id in it can be escaped, single quotes won't work.
If you write more programs, you will know the difference when you die several times ......

There is no difference between double quotation marks in Javascript, as long as they are used in pairs.

Most of the single quotes used in JavaScript are because Javascript and HTML have a lot of dealings with each other. when outputting HTML fragments, you do not need to escape the attribute quotation marks in HTML.

What do you ask about the Xiami language?
In php, single quotes are generally considered to be more efficient than double quotes, because single quotes are completely referenced, and double quotes support variables and wildcards. Therefore, single quotes are recommended for strings.

@ Elan Xie can be written in SQL statements like this?
$ Query = 'select * FROM tablename WHERE id = '. $ id;
Is such a statement more efficient during execution?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.