JavaScript if far from being the best-designed language in the world. I personally often feel myself like in the mine field when coding in it. But it evolves and gets better and better. I can increasingly better express the ideas in JavaScript and I feel it becomes truly powerful and pretty pleasant language to use. Here, I want to share how today one can calculate the sum of the array of numbers. The example is contrived but this example is always used in the schools…Continue Reading “Using array destructuring and recursion to make your JavaScript algorithms shine”

TypeScript, although very promising language, does not solve fundamental JavaScript’s issue (feature?) with “this” property binding. TypeScript can lead to unfortunate errors since it is heavily used by people coming from C#/Java communities, who bring coding patterns with them. Let’s have a look at code example from TypeScript playground: class Greeter { greeting: string; constructor(message: string) { this.greeting = message; } greet() { return “Hello, ” + this.greeting; } } let greeter = new Greeter(“Alexander”); console.log(greeter.greet()); // Hello, Alexander Now, lets make slight change to…Continue Reading “TypeScript is actually JavaScript and one still has to be careful”

From time to time I do the same error when trying to export some variable from whatever kind of JavaScript module: function createStudent(aName) { var name = aName; function setName(aName) { name = aName; } function getName(aName) { return name; } return { name: name, setName: setName, getName: getName }; } var s = createStudent(“Alexander”); console.log(; //Alexander s.setName(“Ivan”); console.log(; //Alexander. Why?? console.log(s.getName()); //Ivan. Yay! 🙂 Having 13 years of coding experience does not save me from the moment of confusion here :-). If you are…Continue Reading “Exporting a variable from JavaScript module”