When a variable is declared but unused, the compiler emits a warning:
let x = 5;If needed, this can be silenced by prefixing the variable’s name with an
underscore (_) character as suggested by the compiler’s message.
This may be useful when an implementation is not yet finalized, and we just
want to avoid too much warnings.
Example:
let _x = 5;We could even replace the whole variable’s name with a single underscore character. This is particulary useful when ignoring a certain value, or the returned value of a function. Example:
let _ = 5;