Code Notes

JavaScript

Tips and tricks I learned throughout the years.

JavaScript looks familiar to many engineers, but behaves differently in all the places that matter. Here I share practical lessons that help whether you're just getting started or already shipping in production.

JavaScript tips - Page 4

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 java script. Users de…

Read article

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. Instead we have to get the co…

Read article

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['foo']; // bar I wis…

Read article

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; } return (num …

Read article

How to detect when the images are loaded

It is simple to load images to the page using JavaScript. We can create it using two methods then append it to the DOM. var img1 = document.createElement("img"); var img2 = new Image(); img1.src = "path/to/image1.jpg"; …

Read article

Previous Page 4 Next