DEV Community

Cover image for JavaScript Quick Tip: Named functions for sane debugging

JavaScript Quick Tip: Named functions for sane debugging

Sunny Singh on March 12, 2019

Debugging is not something that you think about at the time of writing your code, but doing so can drammatically save you from frustration later. ...
Collapse
 
jorluiseptor profile image
Jorge Sepulveda

Thanks! That's exactly what I was seeing and spent extra time figuring out where the error was.

Collapse
 
sunnysingh profile image
Sunny Singh

Glad it helped Jorge!

Collapse
 
mandrewdarts profile image
M. Andrew Darts • Edited

Great tip! Thanks for breaking it down 🤘

Collapse
 
beernutz profile image
beernutz

I wonder if there is any downside to doing this? Is the function instantiated differently? Does it use more memory? Either way I DO like the idea.

Collapse
 
sunnysingh profile image
Sunny Singh

I don't think there are performance downsides to using named functions except in scenarios where you want to micro-optimize within a framework or tool. Even if there are, a compiler or minifier can surely fix that without having to manually change your code.

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

TDD (test driven development) would hopefully help you think about debugging before logic. I confess I am guilty of DDT (development driven tests) 🤣. Dry British whit for you there.

Collapse
 
sunnysingh profile image
Sunny Singh

Yeah TDD can help with that for sure, but I definitely still do DDT as well haha.