Although ES6 was released a while ago, I’m still discovering some small features which I wasn’t aware of, some more important then others but they all can improve your quality code.

Strings functions

The repeat() function

They are languages like Ruby and Python were you can do stuff like "hello" * 2 which will then give you 'hellohello', there wasn't anything like that before in Javacript, from ES6, they introduce repeat().

const hello = 'Hello';

hello.repeat(2); // "HelloHello"

hello.repeat(2*2); // "HelloHelloHelloHello"

String injection fuctions

There is three different and usefull methods which can be apply in common situatuions: includes(), startsWith() and endsWith()

startsWith()

It takes two arguments, the string we are targeting and the position number.

  let text = 'String injection function';

  text.startsWith('String'); // true
  text.startsWith('injection'); // flase
  text.startsWith('injection', 8); // true

endsWith()

Pretty much the same as startWidth but the position number reads from right to left.

  ....
  text.endsWith('String'); // flase
  text.endsWith('function'); // true
  text.endsWith('function', 24); // true

includes()

I won't call this one an unknown feature, but still worth mentioning.

  ...
  text.includes('fuction') //true
  text.includes('') // true
  text.includes('number') // false

Number functions

Working with integers could be quite important, depending on what you are doing, you need to take care of different situations.

Number.isInteger()

Is common to use Math.floor() when working with decimals, ES6 added a helper called Number.isInteger() that could be helpful as well.

  ...
  Number.isInteger(5); // true
  Number.isInteger(5,5); // false

  Number.isInteger(NaN); // false
  Number.isInteger(Infinity); // false

Number.isNaN()

The isNaN() function was broken for years, now is being fix when you use Number.isNaN().

  ...
  isNaN(NaN)// true
  isNaN('NaN')// true

  Number.isNaN(NaN)// true
  Number.isNaN('NaN')// false

Objects functions

Object.is()

We usually use ==== for equality comparison in most cases ans it won't change soon, however, in ES6 the helper Object.is() is even more strict.

  const x = NaN, y = 0, z = -0

  x === x // false
  y === z // true

  Object.is(x, x) // true
  Object.is(y, z) // false

Object.setPrototypeOf()

Delegating responsibilities in a smart way.

  const obj = {
    hello(name) { console.log(`Hello ${name}`) } 
  };

  const obj2 = {};

  Object.setPrototypeOf(obj2, obj);

  obj2.hello('Billy');
  // Hello Billy