How I discovered that debugger is my friend!

Ekaterina
2 min readMay 10, 2021

I am sure all those learning programming once in a while came across a situation when everything seems perfect in your code, but it still does not produce the result you want and there are no error messages to help you! Have you tried running the code with the debugger? If not, you should! It certainly helped me.

Problem

I was trying to filter my array based on various filters. The code looked correct. I have looped through filters array and checked if the filter is active and whether it matches the filter name. All looked good and logical. If the filter is “done” and fliter.status is true, my array should be filtered! Yet, it did not work. I could not figure out why!

Debugging with breakpoints

To understand my problem I decided to run the VS Code Debugger. First I set up a breakpoint to see whether I get into my forEach statement. Once I realised I did, I set up breakpoints for each of my if statements just to see whether I even get into them. I ran the debugger and understood that I do not get into my if statements! So all of them are false!

Once I understood that, I realised that I did not write my if statements correctly. Every filter I have is an object. And I am not checking the filter’s name, but the whole object!

Silly mistake that messed up my filtering!

Solution

So, the solution presented itself immediately!

There is no better feeling than understanding the problem and finding a solution! And there is no better tool to help you than a debugger!!

--

--