aaron248
asked on
Empty Values in a JavaScript JSON Object
There will be some javascript on every page of my site that gets a JSON object embedded into a <script/> tag in my html. Sometimes the JSON object will look like this:
other times there will be no "sale-price". Is it better to leave the "sale-price" out altogether or can I do something like this:
What's the best practice? Using the keyword "null" or leaving it blank and just have the comma?
Thanks in advance!
Aaron
var pageData = {
"navigation" : {
"pageName" : "anypage-123",
"pageSite" : "anysite.com",
"pageType" : "any",
"sale-price" : 27.50
"price" : 55.00
}
};
other times there will be no "sale-price". Is it better to leave the "sale-price" out altogether or can I do something like this:
var pageData = {
"navigation" : {
"pageName" : "anypage-123",
"pageSite" : "anysite.com",
"pageType" : "any",
"sale-price" : null,
"price" : "55.00"
}
};
What's the best practice? Using the keyword "null" or leaving it blank and just have the comma?
Thanks in advance!
Aaron
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.