Recently, I've created a dynamic story where I wanted an event to trigger when an element is in view. The solution was simple, but it's easy to make a mistake and drain your website's performance. Let's break it down int…
Read article
I wanted to write a function that allowed me to wait for a specific time to run the code. The quick and dirty way to do it was to use setTimeout and nest callbacks. For example, at the end of an action, I would like to p…
Read article
I find it very annoying when I use an instant search field and each key I press creates a new state. What this means every single time I hit the back button, it removes a single key from the URL. I have to press the back…
Read article
At some point, every web application needs an overlay. A sort of pop-up that obscures the background and asks the user to perform an action. Here is how you do it.
First you create the HTML, give the overlay an absolute …
Read article
TL;DR;
You are accessing a property of an object that is null. For example, document.getElementById('stuff') returns null. So adding .value will cause the error.
You are trying to access a DOM element before the DOM is …
Read article
There is a clear reason why you should use prototypes when creating classes in JavaScript.
> They use less memory.
When a method is defined using this.methodName a new copy is created every time a new object is insta…
Read article
In JavaScript, like in many other languages a loop can be defined in many ways. The standard of course is the for-loop, the while loop, or do while loop. They are all natively implemented in JavaScript and benefit from t…
Read article
This is a common error in JavaScript, and it is hard to understand at first why it happens. But if you bear with me and remember that Bugs are a good thing you will be on your way in no time.
> ### TL;DR
> The Jav…
Read article