There are several reasons why declaring a const constant. First of all, he tells anyone who reads the code that the value will remain unchanged, that the udentifier is just an alias for the value. Secondly, the optimizer will have an easier task to find out if the identifier value can change between two readings. Declaring this value makes it very simple, because it cannot change. For me, the old reason is more important. Writing code that clearly shows intent is one of the developerβs most important habits.
source
share