I took the example code the lesson gave me, took out the "const" and it still worked. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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 Answers
+ 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