Spectory Blog

Diving into JavaScript Closures

By Amitai B, Jul 27 2016

JavaScript is an amazing programing language, it has beautiful parts. But it also contains very confusing and complex parts. Closures and scopes are probably two of the them. In his book JavaScript: The Good Parts (a must read for every web developer!) Douglas Crockford regrads the JavaScript Scope as one of the awfull parts. I couldn’t agree more. As a software developer that started his programming with languages such as C/C++, I had hard times getting used to it and prevent bugs and errors in my programs. But where there’s a pitfall, there is also a challenge, and one of the best way to handle this challenge is using Closures. On the contrary to scopes, Closures are one of the best features in JavaScript that adds a lot of depth and opportunities to develop clean and good code. But Closures are not easy to grasp and understand. In this blog post I will explain what is a closure, how and when to use it.

Read More