I know it has been asked and answered how to set a default parameter for a javascript function by Tilendor
I was wondering if I had a function containing a series of booleans.
For example, a function called 'anAnimal' and as a default I set a value of false to three propertys.
fly, swim, and climb.
What would I do if I just want to pass in an argument of true to my property called climb?
Currently when calling in the method I have to pass in a value of false for fly and swim even though I have already predefined them as false.
This is what I am attempting and I would like the result to say true instead of false
function anAnimal (fly = false, swim = false, climb = false) {
this.canFly = fly;
this.canSwim = swim;
this.canClimb = climb;
}
var cat = new anAnimal(true)
var theCat = 'This cat can climb: ' + cat.canClimb;
document.write(theCat);