One way is to check if the parameter value is undefined
and if so then assign a value.
function plotChart(data, xlabel, ylabel, chart_type) {
if (typeof chart_type === 'undefined') {
chart_type = 'l';
}
}
Also EcmaScript 2016 (ES6) offers Default Parameters. Since some browser don't yet support this feature you can use a transpiler such as babel to convert the code to ES5.
To make it work like in your python example you would have to pass an object containing the values instead of individual parameters.
function plotChart(options) {
var data = options.data;
var xlabel = options.xlabel;
var ylabel = options.ylabel;
var chart_type = (typeof options.chart_type === 'undefined' ? 'l' : options.chart_type);
}
Example usage
plotChart({
xlabel: 'my label',
chart_type: 'pie'
});