Tips and tricks I learned throughout the years.

JavaScript is different. Experienced users that come from other languages have a hard time learning it, because it looks similar but operates differently. Here I will share all the insights I learned in the past few years. You will find it quite useful whether you programmed for years, or are just getting started.

Latest JavaScript Tips

Uncaught TypeError: Cannot read property of null

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 eleme…


Why Use Prototype in JavaScript

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…


Optimization: Minimize look-ups in for loops.

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 JavaScrip…


Uncaught SyntaxError: Unexpected token

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. > #…


Magical JavaScript Live Collection

JavaScript live collection is a subject that is rarely talked about. Earlier I had written about a caveat when using them. It did help people but one of the problem is that most didn't understand what…


Creating a class in JavaScript

It comes to a surprise that JavaScript, the most popular language on the web, has the most unconventional method for creating a class. In most object oriented programming languages, classes follow a c…


When to use Object.hasOwnProperty

In JavaScript, everything is an object. This is amazing because you never have to ask yourself if something is an object. The answer is always Yes. Let's look at a few examples: // a number is an obj…


Loading jQuery asynchronously

The recommended way to load jQuery is with a script tag. You place it on the bottom of your page and make sure every script that depends on it are loaded after. However, what happens when you want to …