How to iterate easily over object properties in JavaScript

I like my code to be elegant and efficient. The logic should be straightforward to make it hard for bugs to hide, the dependencies minimal to ease maintenance [...]. Clean code does one thing well. Bjarne Stroustrup, inventor of C++ In the same period of ECMAScript 2016 release in June 2016, JavaScript developers are happy to know that another bunch of awesome proposals reached the stage… Continue reading

Make your JavaScript code shine: knockout old ES5 hacks (Part 2)

Many developers were frustrated about JavaScript, especially before ECMAScript 2015 standard. And they had the right too: the language is known for its weakness and initial design drawbacks. How did it happen? At the beginning of the web era, no one did know how exactly the web will look in 10 - 15 years. And especially that a small Java's brother JavaScript will become the… Continue reading

Make your JavaScript code shine: knockout old ES5 hacks

It's known that before ECMAScript 2015 JavaScript language was tricky. For simple scripts ES5 code works fine. But as soon as the application complexity grows, you start to feel that the lack of language constructs is making your code unpleasant. Because you have to implement the application requirements, you can't jump over the parts of code that are troublesome to implement in ES5 style. The… Continue reading

Detailed overview of well-known symbols

Symbol is a new primitive type available from ECMAScript 2015, which allow to create unique identifiers let uniqueKey = Symbol('SymbolName'). Symbols can be used as keys of properties in objects. A list of symbols that JavaScript treats specially is published as well-known symbols. Well-known symbols are used by built-in JavaScript algorithms. For example Symbol.iterator is utilized to iterate over items in arrays, strings, or… Continue reading

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

Six 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