locked
quotation and double quotation! RRS feed

  • Question

  • User1241685987 posted

    Hi,

    When should i used quotation and double quotation? Can you give me syntax? Thanks

    for(i = 0; i<arr.length; i++) {
    out += '<a href="' + arr[i].url + '">' +
    arr[i].display + '</a><br>';

    Thursday, July 31, 2014 1:56 AM

Answers

  • User-821857111 posted

    It makes no difference. I tend to use single quotes to delimit strings and double quotes to represent quotes. The jQuery docs on the other hand use double quotes to delimit strings. The main thing is to be consistent.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 31, 2014 2:05 AM
  • User1283497924 posted

    When you are preparing any string on that case use double quotation .

    Eg:

    string str="This is test";

    and when you want to put some string value into sinlge quotes.

    eG:

    string str="This is 'test'.";

    Output: This is 'test'.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 31, 2014 2:09 AM
  • User614396724 posted

    Hi,

    U can Use like this

    \' - single quote
    \" - double quote

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 31, 2014 2:23 AM
  • User-821857111 posted

    var out = "";
    var i;
    for(i = 0; i<arr.length; i++) {
    out += '<a href="' + arr[i].url + '">' + arr[i].display + '</a><br>';
    }
    document.getElementById("id01").innerHTML = out;
    }

    Here, you are alternating between two options which is not advised. That will cause confusion.

    var out = '';

    Here, you declare a string. I use single quotes for delimiting strings (denoting where they begin and end).

    out += '<a href="' + arr[i].url + '">' + arr[i].display + '</a><br>'

    Now the line above in consistent as single quotes are being used to delimit the string. The Double quotes appears as quotes in the string., IF you use single quotes to delimit, and you want to include a single quote in the string, you need to escape it with a backslash \:

    out = 'Your\'re using single quotes';

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 31, 2014 4:34 AM

All replies

  • User-821857111 posted

    It makes no difference. I tend to use single quotes to delimit strings and double quotes to represent quotes. The jQuery docs on the other hand use double quotes to delimit strings. The main thing is to be consistent.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 31, 2014 2:05 AM
  • User1283497924 posted

    When you are preparing any string on that case use double quotation .

    Eg:

    string str="This is test";

    and when you want to put some string value into sinlge quotes.

    eG:

    string str="This is 'test'.";

    Output: This is 'test'.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 31, 2014 2:09 AM
  • User614396724 posted

    Hi,

    U can Use like this

    \' - single quote
    \" - double quote

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 31, 2014 2:23 AM
  • User1241685987 posted

    Thanks,

    But can you explain it? i don't understand when i used ' or " and what is the used?

    <!DOCTYPE html>
    <html>
    <body>

    <div id="id01"></div>
    <script>
    function myFunction(arr) {
    var out = "";
    var i;
    for(i = 0; i<arr.length; i++) {
    out += '<a href="' + arr[i].url + '">' + arr[i].display + '</a><br>';
    }
    document.getElementById("id01").innerHTML = out;
    }
    </script>

    <script src="myTutorials.js"></script>

    </body>
    </html>

    Thursday, July 31, 2014 3:14 AM
  • User-821857111 posted

    var out = "";
    var i;
    for(i = 0; i<arr.length; i++) {
    out += '<a href="' + arr[i].url + '">' + arr[i].display + '</a><br>';
    }
    document.getElementById("id01").innerHTML = out;
    }

    Here, you are alternating between two options which is not advised. That will cause confusion.

    var out = '';

    Here, you declare a string. I use single quotes for delimiting strings (denoting where they begin and end).

    out += '<a href="' + arr[i].url + '">' + arr[i].display + '</a><br>'

    Now the line above in consistent as single quotes are being used to delimit the string. The Double quotes appears as quotes in the string., IF you use single quotes to delimit, and you want to include a single quote in the string, you need to escape it with a backslash \:

    out = 'Your\'re using single quotes';

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 31, 2014 4:34 AM