Gaurav Srivastava Gaurav Srivastava - 24 days ago 7
Javascript Question

IE returning error in javascript function

this function works in all browser:-

$scope.changeTime = function(date,format='D MMMM, YYYY'){
var time= moment(date, 'YYYY-MM-DD').format(format);

return time;
}


but Internet explorer throws this error-

*"Expected ')'"

i suspect internet explorer doesn't take default param value in javascript function.

how can make it work in Internet explorer.

Answer

Default parameter values are not yet supported in all browsers. Instead use something like this:

$scope.changeTime = function(date, theFormat) {
    var format = theFormat || 'YYYY-MD-DD';
    var time = moment(date, 'YYYY-MM-DD').format(format);

    return time;
}