How to write quotation marks in JavaScript

前端 未结 5 1068
小蘑菇
小蘑菇 2020-12-15 10:25

Hi I want to do the following, but don\'t know how to write the quotation marks

allSearchResults[0]=\"
  • CXS101289/
  • 5条回答
    •  甜味超标
      2020-12-15 10:49

      Two ways times two

      1. mix single and double quotes:

        // single outside, double inside quotes
        allSearchResults[0] = '
      2. CXS101289/
      3. ';

        or

        // double outside, single inside quotes
        allSearchResults[0] = "
      4. CXS101289/
      5. ";
      6. use one set of quotes but escape inside ones:

        // double escaped quotes
        allSearchResults[0] = "
      7. CXS101289/
      8. ";

        or

        // single escaped quotes
        allSearchResults[0] = '
      9. CXS101289/
      10. ';

      First approach with mixing is usually easier, because it presents less work since you only have to change the opening and closing quote.

    提交回复
    热议问题