Functions become very powerful and more reusable with arguments. You can customize the behaviour inside based on the passed arguments which makes it convenient as well.
Syntax
@function name(args) {
...
}
The function must be called with same number of arguments unless the arguments are optional.
What are Optional Arguments?
Just like JavaScript Optional Arguments or any other programming language, Optional Arguments are optional to pass.
Without Optional Arguments, each and every arguments in the function declaration are required to be passed. With Optional Arguments, no need to pass if you don’t have any value. Later when you have a vale, you can pass it.
You can make any argument optional by defining a default value for it.
Here’s an example from Sass official docs:
What are Keyword Arguments?
Keyword Arguments are nothing but arguments passed with keywords.
It makes easier to understand when you make a function call and less chances of making a mistake in case you are not aware of the keyword expected type.
Here’s another example from Sass official docs with some modification:
You have to be really careful about changing names for arguments since users might pass arguments using an old name and it’ll eventually break your code!
Renaming tip
Keep the old name as an optional argument and show a warning to users who passes argument using that keyword. Once users know that, they will migrate it and at the end you can remove the old name completely.
arguments examples functions keywords Optional arguments sass