Welcome to the Treehouse Community
Looking to learn something new?
Mark VonGyer21,215 Points
Why would I use default value?
Not sure why I would use the default value.
Would you call a function that needs data passed in if you aren't going to pass anything in?
Anyone used this in practice?
Kevin Korte28,135 Points
Sure, just about every CMS uses this. Take wordpress for example, there are probably literally hundreds of functions that are defined in Wordpress and available to use. Most of all of these functions have sensible defaults if arguments are not passed in.
Outside of WP, let's say you had a function that generated a menu. Most menus are generally the alike. This one function could generate two different menus depending on the arguments passed through.
A function is for reusable bits of code. Optional arguments just give the function the ability to be more customizable while still being DRY.