Question
What’s the benefit of using a const
? Why wouldn’t you want to edit a variable?
Answer
The main benefit of const
is that you can rest assured that you won’t accidentally edit the variable elsewhere in your code that you intend on never changing value. An additional benefit, and possibly the more important benefit, you can be more assured that there will be less tampering with your code as others cannot change these values either. In general, if you know you won’t be redefining a variable elsewhere in your code, it is advised to use const
.