Hemanth's Scribes

javascript

Superfluous Patterns of JavaScript

Author Photo

Hemanth HM

Thumbnail

Things we can get rid of with ES6:

No More String Concatenation with +

// Old
console.log("Hello " + fname + "." + lname);

// New with template strings
console.log(`Hello ${fname}.${lname}`);

No More function Keyword

// Old
var greet = function(name) { return "Hello " + name; };

// New with arrow functions
let greet = name => `Hello ${name}`;

No More arguments Conversion

// Old
[].slice.call(arguments).sort();

// New with rest parameters
let sortArgs = (...args) => args.sort();

No More || Default Trick

// Old
namespace = namespace || { utils: {}, core: {} };

// New with default parameters
let fn = (namespace = { utils: {}, core: {} }) => '';

No More var that = this

Arrow functions preserve lexical this!

#javascript#es6
Author Photo

About Hemanth HM

Hemanth HM is a Sr. Machine Learning Manager at PayPal, Google Developer Expert, TC39 delegate, FOSS advocate, and community leader with a passion for programming, AI, and open-source contributions.