JavaScript Loops and Scope

JavaScript is a versatile programming language that offers a lot of flexibility to developers. However, there is one feature of JavaScript that can cause some confusion when it comes to loops and scoping. In this article, we will explore this feature and provide some tricks to work around it using var and let declarations. Let’s start with an example: const operations = [] for (var i = 0; i < 5; i++) { operations....

Passing undefined to JavaScript Immediately-invoked Function Expressions

In older code, you may come across a situation where undefined is intentionally passed to a function. Why was this done? I stumbled upon this interesting technique while watching the well-known Paul Irish video about the jQuery source code. This video is from a different era, being 9 years old at the time of writing, and the jQuery source code has since changed, so you won’t find this trick in there anymore....