I want to make default parameter in javascript , so can i ?
jm.toInt = function (num, base=10) {
return parseInt(num,base);
}
I want to make default parameter in javascript , so can i ?
jm.toInt = function (num, base=10) {
return parseInt(num,base);
}
ES6 support default parameters, but ES5 not, you can use transpilers (like babel) to use ES6 today
It is part of ES6, but as of now, not widely supported so you can do something like
jm.toInt = function(num, base) {
return parseInt(num, arguments.length > 1 ? base : 10);
}
arguments.length > 1 ?
rather then simply base ?