AlbertoMontalesi/The-complete-guide-to-modern-JavaScript

Chapter 3: Default function arguments

jzrchilel opened this issue · 1 comments

Hi Alberto!

I think that something you can add to this chapter as a warning or whatever you want to call it, is that default parameters are only applied if the arguments is undefined.

Try this:

const printText = (text = 'default') => console.log(text)

printText('Alberto')
// prints ---> 'Alberto'

printText(undefined)
// prints ---> 'default'

printText(false)
// prints ---> false

printText(null)
// prints ---> null

printText('')
// prints ---> ''

So an alternative to this, could be to use the || operator.

Regards!

Sorry for the late reply. Yes, I will definitely add it to the chapter, thank you