Sample Video Frame
06: Variables
In programming there's a concept of a "magic number". This is a number that's some constant or setting which is simply sitting there in the code with no explanation as to what it is, or why it is that number. Programmers over the years have learned to hate magic numbers for three reasons:
- Magic numbers don't explain what they are or why the exist. You just see
0xDEADCAFE
and think, "What? Why did someone use this number here." - Magic numbers are difficult to update and fix later. Imagine you now have to be 100% positive you've replaced all
0xDEADCAFE
numbers with0x5637CC
. Now you have to search and replace all over, but what if0xDEADCAFE
is used for more than one thing? Now you can't just replace them, you have to check each one. - Magic numbers simply don't scale as the code and team of people grows. Cognitively it's difficult to keep all of the magic numbers in one person's head, let alone correctly share this information with others reliably. As the quantity of magic numbers increases, your ability to remember each one diminishes.
The solution programmers have for magic numbers is to simply give them name like this:
image_tag = 0xDEADCAFE
Learn JavaScript Today
Register today for the Early Access course and get the all currently available videos and lessons, plus all future modules for no extra charge.
Still Not Sure? Check out more curriculum.