JavaScript variables lifecycle: why let is not hoisted

Hoisting is the process of virtually moving the variable or function definition to the beginning of the scope, usually for variable statement var and function declaration function fun() {...}. When let (and also const and class, which have similar declaration behavior as let) declarations were introduced by ES2015, many developers including myself were using the hoisting definition to describe how variables are accessed. But after more… Continue reading

Why object literals in JavaScript are cool

Before ECMAScript 2015 object literals (also named object initializers) in JavaScript were quite elementary. It was possible to define 2 types of properties: Pairs of property names and related values { name1: value1 } Getters { get name(){..} } and setters { set name(val){..} } for computed property values Sadly, the object literal possibilities match into a single example: Try in JS Bin var myObject = { myString: 'value 1', get myNumber(… Continue reading

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