Quotes or No Quotes?

Quotes or No Quotes?

kyriebellekyriebelle Posts: 5Questions: 2Answers: 0

Hi all!
I have a question about the DataTables manual/documentation. If this has been asked before, I apologize. I didn't see it.

In the manual where sample code is being shown, I've noticed the type of quotation mark being used is different.

Sometimes it's double quotes:

$(document).ready(function() {
    $('#example').DataTable( {
        "ajax": "data/objects.txt",
        "columns": [
            { "data": "name" },
            { "data": "position" },
            { "data": "office" },
            { "data": "extn" },
            { "data": "start_date" },
            { "data": "salary" }
        ]
    } );
} );

sometimes it's single quotes:

$(document).ready(function() {
    $('#example').DataTable( {
        'ajax': "data/objects.txt",
        'columns': [
            { 'data': "name" },
            { 'data': "position" },
            { 'data': "office" },
            { 'data': "extn" },
            { 'data': "start_date" },
            { 'data': "salary" }
        ]
    } );
} );

and sometimes it's no quotes

$(document).ready(function() {
    $('#example').DataTable( {
        ajax: "data/objects.txt",
        columns: [
            { data: "name" },
            { data: "position" },
            { data: "office" },
            { data: "extn" },
            { data: "start_date" },
            { data: "salary" }
        ]
    } );
} );

Which is the correct way to do it? Especially if you want to return a json object.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,213Questions: 1Answers: 10,415 Site admin
    Answer ✓

    There isn’t a correct way to do it - all are equally valid Javascript. Personally I prefer the no-quote style, but when I originally wrote DataTable I tended to use double quotes, as that made it valid JSON as well.

    You might be interested in taking a look at Prettier which will format code to be a consistent style.

    Allan

  • kyriebellekyriebelle Posts: 5Questions: 2Answers: 0

    Ok, gotcha. I'll have to check that out. Thanks!

This discussion has been closed.