Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write quotation marks in JavaScript

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

allSearchResults[0]="<li><a href="CXS101289/"> CXS101289/</a></li>";

It shall be quotation marks where the currently are.

like image 326
john Avatar asked Apr 14 '11 10:04

john


People also ask

What is quotation in JavaScript?

In JavaScript, single quotes ( '' ) and double quotes ( “” ) are used to create string literals. Most developers use single or double quotes as they prefer, and sometimes they let their code formatters decide what to use.

Is JavaScript single or double quotes?

Both single (' ') and double (" ") quotes are used to represent a string in Javascript. Choosing a quoting style is up to you and there is no special semantics for one style over the other. Nevertheless, it is important to note that there is no type for a single character in javascript, everything is always a string!

How do you put quotation marks in HTML?

We use <q> tag, to add short quotation marks in HTML. And if we want to quote for multiple lines, use <blockquote> tag. We can also use the cite attribute inside the <blockquote> tag to indicate the source of the quotation in URL form.


1 Answers

Two ways times two

  1. mix single and double quotes:

    // single outside, double inside quotes
    allSearchResults[0] = '<li><a href="CXS101289/">CXS101289/</a></li>';
    

    or

    // double outside, single inside quotes
    allSearchResults[0] = "<li><a href='CXS101289/'>CXS101289/</a></li>";
    
  2. use one set of quotes but escape inside ones:

    // double escaped quotes
    allSearchResults[0] = "<li><a href=\"CXS101289/\">CXS101289/</a></li>";
    

    or

    // single escaped quotes
    allSearchResults[0] = '<li><a href=\'CXS101289/\'>CXS101289/</a></li>';
    

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

like image 163
Robert Koritnik Avatar answered Sep 18 '22 06:09

Robert Koritnik