Must know details about ES2016 features

Good news, in June 2016 ECMAScript 2016 was approved. It contains the features that passed the stage 4, which means finished, of the TC39 process: The array method includes() The exponentiation operator base ** exponent This edition is smaller than ECMAScript 2015, but it doesn't mean less important. Still it has details that you should know before using the new features. The new method array.includes(… Continue reading

Yes. JavaScript rises.

It is hard to find a developer who didn't write JavaScript code. These days ECMAScript 2015 makes JavaScript the supreme leader of the Web. Let's see how JavaScript rises from a complementary language back in 1995 until these days, when it becomes very popular and conquerors the client and server side web development. The dark JavaScript was created in about 10 days by Brendan Eich… Continue reading

Power up the array creation in JavaScript

The array is an ordered collection of objects or primitive types. It's hard to imagine an application that doesn't use this data structure. Working with arrays consists in the following phases: Initialize the array and setup the initial elements Access the array elements by index Add new elements Remove existing elements The current article covers the array initialization and setting the initial elements. The basic… Continue reading

6 ways to declare JavaScript functions

A function is a parametric block of code defined one time and called any number of times later. In JavaScript a function is composed and influenced by many components: JavaScript code that forms the function body The list of function parameters The variables accessible from the outer scope The returned value The context this when the function is invoked Named or anonymous function The variable… Continue reading

How three dots changed JavaScript

When accessing arguments values in a function call, I always felt uncomfortable with arguments object. Its hardcoded name makes difficult to access arguments of an outer function in an inner one (which defines its own arguments). Even worse JavaScript provides it as an array-like object. It is not possible to use array methods like .map() or .forEach() directly on it. To access arguments from the… Continue reading

When 'not' to use arrow functions

It is a pleasure to see the evolution of the programming language you code every day. Learning from mistakes, searching for better implementation, creating new features is what makes the progress from version to version. This is happening to JavaScript these years, when ECMAScript 6 brings the language to a new level of usability: arrow functions, classes and a lot more. And this is great!… Continue reading

JavaScript variables hoisting in details

Variables in a program are everywhere. They are small pieces of data and logic that always interact with each other: and this activity makes the application alive. In JavaScript an important aspect of working with variables is hoisting, which defines when a variable is accessible. If you're looking for a detailed description of this aspect, then you're in the right place. Let's begin. 1. Introduction… Continue reading

Gentle explanation of 'this' keyword in JavaScript

1. The mystery of this A lot of time this keyword was a mystery for me and many starting JavaScript developers. It is a powerful feature, but requires efforts to be understood. From a background like Java, PHP or other standard language, this is seen as an instance of the current object in the class method: no more and no less. Mostly, it cannot be… Continue reading

Inheritance in JavaScript: understanding the constructor property

JavaScript has an interesting inheritance mechanism: prototypal. Most of the starting JavaScript developers have hard time understanding it, as well as I had. All types in JavaScript (except the null and undefined values) have a constructor property, which is a part of the inheritance. For example: var num = 150; num.constructor === Number // => true var obj = {}; str.constructor === Object // => true var reg = /\d/g;… Continue reading

Catch the XMLHttpRequest in plain JavaScript

When coding Chrome extensions, sometimes I need to catch the event when JavaScript application starts a XMLHttpRequest (XHR) and finishes. Because the injected script into web page context do not modify the original application, this is hard to do, because pure XHR does not trigger global events. Some libraries, for example jQuery, do trigger global events ajaxStart and ajaxStop, and even offers global ajax events… Continue reading