1024px-Flatirons_Winter_Sunrise_edit_2

How to Add/Remove CSS classes using JavaScript

This post will demonstrate two approaches for manipulating the classes of an HTML element. The first uses the plain javascript property classList and the second uses jQuery, a popular javascript library. To begin, consider the following document:

The document has one button with an onclick event to toggle the color of the button. The […]

1024px-Flatirons_Winter_Sunrise_edit_2

How to replace all spaces in JavaScript?

In computer programming, “find and replace” is a pretty common task. Any programmer that’s interested in working with textual data should have at least a rudimentary idea of how to write a basic find and replace algorithm. In the JavaScript programming language, find and replace functions are not hard to implement. In the following examples, […]

1024px-Flatirons_Winter_Sunrise_edit_2

How to Check If a Key Exists in a JavaScript Object?

JavaScript objects are comprised of properties. Properties in JavaScript are defined as pairs of keys and values. Keys can be generally thought of as the names of the values stored within JavaScript objects. There are a few different ways in which to check if a specific key exists within a certain object. And depending on […]

1024px-Flatirons_Winter_Sunrise_edit_2

Working with the Date Object in JavaScript

Getting the current date in JavaScript is a piece of cake. The language features a convenient Date object that’s preloaded with all sorts of methods for retrieving temporal values. The syntax is simple enough and the names of the methods, for the most part, are pretty intuitive. In the following examples, I’ll show you how […]

1024px-Flatirons_Winter_Sunrise_edit_2

Working With Promises in AngularJS Services

Let’s talk about working with promises in AngularJS. To start, $q is a great implementation of promises, allowing you work with deferred objects and be more efficient with Ajax calls. $q api has few useful methods, first one is to create new deferred object using $q.defer(), so this object could be resolve in the future […]

1024px-Flatirons_Winter_Sunrise_edit_2

Quick and Dirty JavaScript Closures Guide

Understanding closures is crucial to being a successful javascript developer. The purpose of this post is to provide an introduction to closures, as well as some examples of what you can do with them. This post assumes you have an understanding of how variable scope works in javascript. Put simply, a closure is a nested […]

1024px-Flatirons_Winter_Sunrise_edit_2

Ways to Loop Over an Array in JavaScript

Ways to loop over an array in JavaScript? There are a multitude of ways to loop over an array in JavaScript; some common, some less so. Probably the most familiar ways to loop over an array in JavaScript are the for loop and the while loop; for/in loops will work as well, but are traditionally […]

1024px-Flatirons_Winter_Sunrise_edit_2

== vs. === in Javascript (Abstract vs Strict equality in js)

Testing for equality is fundamental in computer science. And while it seems like a straightforward concept (Thing A is the same as Thing B, or it isn’t) there are some subtleties that can, at first, seem strange. For example, it seems a common source of confusion for those new to javascript is whether to use […]

1024px-Flatirons_Winter_Sunrise_edit_2

How to Clear an Array in JavaScript

Arrays are awesome! They allow you to store multiple values in a convenient, indexed set. In JavaScript, arrays can be declared literally or they can be initialized using the Array constructor function. But wait… What if you want to empty an array instead of creating one? Hmm… perhaps not as straightforward. Have no fear, there are […]

1024px-Flatirons_Winter_Sunrise_edit_2

The Difference Between Ng-show vs. Ng-if

There are a variety of built-in Angular directives for showing and hiding content on a page. Ng-show/ng-hide and ng-if are commonly used directives for doing this. Ng-switch and ng-class could also be used to do this (albeit in different ways). This post will explain how ng-show and ng-if differ in their means of hiding content on a page. Explore Angular Courses