در حال بارگذاری ...

Default Parameters in ES50:40

Okay, so yeah, now what if we wanted a default parameter here? Or in other words, if you do not provide a discount, we will automatically use 10%. A lot of stores have that, in fact, a lot of local stores. So maybe all you have to do is ask for a discount, and they will give you 10%. Okay, well, typically with ES5, you end up having to do something like this. You say, to set a default, we're going to set discount equal to either what you passed in, if anything, otherwise, I will default to 10%. So now if we were to try that out, applyDiscount to 100, and we'll do 40% off, and why don't we alert that? If I switch to the browser, give it a refresh, 40% off of 100 is $60.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟