My two most used ES6 features: const & let, & arrow functions
Posted on 31st May 2019
3 min read•
const and let
Before ES6 variables were declared with the
var keyword like
With ES6 there are two new ways to declare variables, which are
let is the closest to
var as in they both allow the variable to be reassigned.
const makes the variable immutable which means a new value cannot be assigned to that variable.
When I write code, my default is to always use
const, because it makes my code more predictable especially when the file is long. I only use
let when I need the variable to hold a new value further along in the code, which is rare for me. If I had to give a ratio to the
function keyword to declare a function
With arrow functions the same function would look like
Note you can assign an arrow function to
var too but it’s always better to assign it to
Arrow functions also allows for implicit return, so the same function can be shortened to
I found the implicit return of arrow functions specially useful when developing in React as it helps cut down the code written by quite a bit.
let, & arrow functions in detail in the future (I’m itching to talk about the whole
If you enjoyed this post please leave a like or two below!!!