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 6

Parse JSON string, cross browser

JSON stands for JavaScript Object Notation. You would think it would be second nature to parse those strings from your Ajax request, but not so much for older browsers. The modern browsers do have the JSON api that makes…

Read article

String trimming

In modern browsers, JavaScript has a .trim() function on the String object. What it does is simple, it removes the extra white space before and after the string. var text = " I have space before and after "; v…

Read article

Every statement must end with a semicolon;

The JavaScript interpreter is nice enough to add semicolons for us if we forget them. For most places this works, but then you get a bug that is impossible to fix, and the debugger doesn't give you the line number where …

Read article

Combine all variable declarations

It is common to see code where all variables are declared separately in JavaScript. When in a scope, or a function, we have tendency to declare variables in multiple places thinking they are isolated from one another. He…

Read article

Checking if variable is an Array

Since the last time I tackled this issue, there has been some improvements to newer versions of JavaScript. The Array object now has the isArray() method. To check if an object is an array, all you have to do is pass it …

Read article

Previous Page 6 Next