We are using custom datetime picker which till now had to return both date and time. But now the conditions have changed and sometimes I need to return only date so I decided to add an optional parameter. Now the script is this :
var date_format = "dd/mm/yyyy HH:MM:ss";
function viewCalendar(parent, destField, dateOnly) {
if (typeof dateOnly !== "undefined") {
date_format = "dd/mm/yyyy";
}
//more code...
But even though it seems to work (I made only few tries) I don't like this very much, but maybe it's because I'm not used to the way of JavaScript. If it wasn't because of some sample code I would do something like :
var date_format = "dd/mm/yyyy HH:MM:ss";
var dateOnly = true;
function viewCalendar(parent, destField, dateOnly) {
if (typeof dateOnly != true) {
date_format = "dd/mm/yyyy";
}
But the few examples I saw about using optinal parameters in JS I haven't seen something like this. What is the proper way to do this kind of thing i JavaScript?