DEV Community

Cover image for ES6 and Beyond > Part 1

ES6 and Beyond > Part 1

Anand Kumar on April 13, 2019

Hello folks, ES6, pretty much hyped topic these days in front-end world. So, how about learning some cool features of ES6 and Beyond (like, ES7, ES...
Collapse
 
jamesthomson profile image
James Thomson

Good article and good uses cases for pad.

May I suggest a clearer example for let. While your example is correct, I think this really drives block scope context home:

if (true) {
  var foo = 'foo';
  let bar = 'bar';
}

console.log(foo) // foo
console.log(bar) // Uncaught ReferenceError: bar is not defined

Also, regarding const (which is also blocked scoped),

we can not re-assign a value to it

It should be noted that this only applies to the value assignment. Nested values are still mutable:

const foo = {
  value: 'foo'
}

foo.value = 'bar';

console.log(foo.value) // bar

however, the value of a const cannot be changed:

const foo = {
  value: 'foo'
}

foo = {
  value: 'bar'
};

// Uncaught TypeError: Assignment to constant variable.
Collapse
 
elanandkumar profile image
Anand Kumar

Thank you.
I do agree with your examples above. Thanks for providing the same.
I did want to cover mutation and more in depth but on the other hand, I just wanted to keep things simple.

Collapse
 
jamesthomson profile image
James Thomson

Fair enough. It can be hard to keep things simple yet cover all the foundations :)

Thread Thread
 
elanandkumar profile image
Anand Kumar

Thank you.

Collapse
 
amatyas001 profile image
Mátyás Angyal • Edited

String interpolation also called template literals right?
And you can use expressions in the literals like: ${ var_1 + var_2 }

Collapse
 
elanandkumar profile image
Anand Kumar

Yes, and the example given by you works well. Just make sure to use backtick :)