Javascript - Function Declarations (DRY principle)
📖 Read the lesson
Code Life
By Pierre Marsaa
Don't Repeat Yourself
Before each battle, your team does the same three-line warm-up. Three battles, three copies of the same code:
↗️
Loading editor...
↶
▶️ Run
↷
If you want to change one word, you have to change it everywhere. A
function
lets you write the block once, give it a name, and reuse it:
↗️
Loading editor...
↶
▶️ Run
↷
Same output, but the code exists in one place only. Programmers call this the
DRY
principle: Don't Repeat Yourself.
Verify