JavaScript

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.

JavaScript tips — Page 3

Always avoid the DOM

The beauty of nodejs is that you don't have to work with the DOM. On the browser, that's where JavaScript power lies. The only problem is it is terribly slows. DOM access are the most expensive transa…

Read

Creating a router in JavaScript for Nodejs

Every URL you type on this website are handled through one script. It is a common standard with many framework. The script in question is called a Router. It takes any URL you give it, and returns the…

Read

My variables are set to the last index in JavaScript

JavaScript is known to host some quirky behavior. Most of the time however, all it takes is getting familiar with it to understand what is really happening and how to work with it. New and experience…

Read

Calling a function out of scope

With the advent of jQuery, coding in JavaScript became accessible to almost everybody. But with it came some very fundamental errors that could have been avoided if the person read the very basic of j…

Read

Get computed style

Sometimes you want to get the width of an element, and the obvious way of getting it does not work. element.style.width; // (empty string) Yeah, I know it should be this easy but it is not. Instea…

Read

Accessing URL parameters in JavaScript

I have worked with PHP extensively and it is very convenient to have all the URL parameters automatically assigned to the global array $_GET. Here is an example: http://www.example.org/?foo=bar $_GET…

Read

Calling a function that has no name

You can make use of recursion easily in JavaScript. Let's try it with factorials: function factorial(num){ if (num < 0) { return -1; } else if (num == 0) { return 1; …

Read

Making fast cross-domain requests when the browser is leaving

There are times you want to make a very quick web request and don't care about the response looks like. It is possible to make requests using Ajax, but we still get a response. One trick you will see…

Read

Photography