Should a Parameter be const or immutable?

This lesson explains when a parameter should be const and when it should be immutable.

Our discussion so far shows that because they are more flexible, const parameters should be preferred over immutable parameters. This is not always true.
const erases the information about whether the original variable was mutable or immutable. This information is hidden even from the compiler.

A consequence of this fact is that const parameters cannot be passed as arguments to functions that take immutable parameters. For example, foo() below cannot pass its const parameter to bar():

Get hands-on with 1200+ tech skills courses.