DEV Community

Cover image for Copying VS Understanding Code
Breeana Payton
Breeana Payton

Posted on

Copying VS Understanding Code

You need to build a countdown timer for your project. You remember something about setInterval but can't quite place it. You open a tab and see Google staring back. There is a choice here. Do you type "setInterval documentation" or "javascript countdown timer"?

One of these teach you the answer while the other will simply give it to you.

Making Sure You Learn

If you googled the javascript countdown timer one of the first links you'll come across is from Stack Overflow and you'll find a function that looks like this:

function timer(){
    var sec = 30;
    var timer = setInterval(function(){
        document.getElementById('safeTimerDisplay').innerHTML='00:'+sec;
        sec--;
        if (sec < 0) {
            clearInterval(timer);
        }
    }, 1000);
}
Enter fullscreen mode Exit fullscreen mode

When coding for companies or bootcamps there will be a code review and you will have to explain your functions. Here are 3 ways that you can prove that you understand the code and make sure that you're learning:

  1. Can you test the code?

    Looking back on that timer function could you write a test for
    it right now? Which testing library would you use? What would
    a fringe case look like? Do you need any extra resources to
    test it?

  2. Can you apply the code within a framework/other language?

    How do you implement this code within React, Angular, or Vue?
    What does this look like in jQuery or Typescript?

  3. Can you explain this function using comments or documentation?

    This is a crucial skill to have when contributing to larger
    code bases and for debugging. Can you break this code up line
    by line and describe what's happening?

If you can answer most of these questions congrats! You are leveling up. If not, congrats! You have a new goal to chase. I am still building my skills in these areas as all developers are. I'm just letting you know what I wish my bootcamp teachers would have told me. If you need any help with these questions feel free to comment below. I'm here to help.

Discussion (0)