Quotes or No Quotes?
Quotes or No Quotes?

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
This discussion has been closed.
Answers
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
Ok, gotcha. I'll have to check that out. Thanks!