I'm new to JavaScript coming from Python background. In Python parameters can be passed as key and value as such:
def printinfo( name, age = 35 ):
print "Name: ", name
print "Age ", age
return;
Then the function could be called as such:
printinfo( age=50, name="miki" )
printinfo( name="miki" )
Can such parameters be passing in JavaScript functions?
I want to be able to pass one or more parameter. For example a JavaScript function as such:
function plotChart(data, xlabel, ylabel, chart_type="l"){
...
}
I want to be able to pass only data and chart type and labels are optional such as :
plotChart(data, chart_type="pie")
Is this possible with JavaScript?
chart_type="pie"
will assign thechart_type
variable outside of the function (or create a global) and pass"pie"
toxlabel
. – Canea