2 ms·
If you declare a variable as `const`, you have to initialize it during declaration. So you have to place the declaration exactly where the value expression beco
by majewsky 10y ago
If you declare a variable as `const`, you have to initialize it during declaration. So you have to place the declaration exactly where the value expression becomes available.
- bluetomcat 10y agoAlso, it acts as a declaration of intent and makes the data dependencies in a function more explicit. If I declare a variable in the middle of a function, I am declaring intent that this variable shouldn't be used in the first half of the function – maybe the data it is supposed to hold cannot be available at that point.