+ 2

I took the example code the lesson gave me, took out the "const" and it still worked.

So why do we even need const?

12th Jun 2017, 1:00 AM
koala 🐨
koala 🐨 - avatar
2 Réponses
+ 8
const makes a variable that cannot be changed while the program runs. Ex: If you want a program to only receive 5 inputs, you can make a const like NUM_INPUTS, and use it in place of 5. If you ever want to change that amount, it's easier to reassign the const than having to find every instance of 5 and changing it.
12th Jun 2017, 1:29 AM
Tamra
Tamra - avatar
+ 2
Const declarations also help the compiler produce faster code.
12th Jun 2017, 1:38 AM
Karl T.
Karl T. - avatar