You can easily introduce default values for the arguments passed to a function.
Consider this function -
|
|
Calling this function without arguments will provide a not-so-pretty string.
|
|
Even if someone had an existential crisis, I doubt they will like to be called ‘undefined’. So - let us change that.
|
|
The ‘or’ statement will -
- retain
name
value if provided - assign ‘world’ to
name
ifname
is falsy
The results are more pleasing.
|
|
You can also use a ternary operator or a full-fledged if
statement, but the above code looks more to the point but at the same time readable.