Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Set a parameter Value of Function Js

PROBLEM =>
I WANT TO ADD VALUE OF PARAM CAPACITY BUT I WANT ALSO NAME PARAM TO BE DEFAULT

function Js(name = 'Mango' , capacity = 40){
console.log(`${name} with a capacity ${capacity} will be delivered !!!`)
}
Js() // .... Correct
Js("Something" , 40) // .... Also Correct

But What if i want to just give value to capacity and set name default

Like this =>

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Js( ..., 55) // Mango with a capacity 55 will be delivered !!!

>Solution :

Put default argument on second place.

function Js(capacity, name= 'Mango'){
console.log(`${name} with a capacity ${capacity} will be delivered !!!`)
}
Js(40) //"Mango with a capacity 40 will be delivered !!!"
Js(40, 'Something else') // "Something else with a capacity 40 will be delivered !!!"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading