

So, when you forget to write the parameter, it won’t return an undefined error because the parameter is already defined in the default. These allow you to define a parameter in advance. When I work in PHP, I usually use default parameters. When playing with strings, the literal string in ES6 looks more organized and well structured than ES5. So simple! It’s a really huge difference between the old syntax and ES6. We don’t have to use the plus (+) operator to concatenate strings, or when we want to use a variable inside a string. Template literals or template strings are pretty cool. You can use the same with filter and reduce. With ES6 you can write shorter and smarter code. The map function with arrows looks more clear and readable than map in ES5. Instead of using this:Īs you see, the arrow function seems more readable and clean! You won’t need to use the old syntax anymore.Īlso, you can use Arrow function with map, filter, and reduce built-in functions. The arrow function is really awesome, and makes your code more readable, more structured, and look like modern code. It means that the variable is only available within its scope. Let is the same as const in that both are blocked-scope. Let can be reassigned and take new value. If you try to give it a new value, it will return you an error. In the code above, const will not change and cannot be reassigned. It’s always preferable to use const when don’t want to reassign the variable.

For example, when we have a single button that fires an event, or when you want to select an HTML element in JavaScript, use const instead of var. This is really useful for targeting the selectors. In other words, it’s an immutable variable except when it used with objects.

Once used, the variable can’t be reassigned. const and letĬonst is a new keyword in ES6 for declaring variables. ES6 introduces us to many great features like arrow functions, template strings, class destruction, Modules… and more. It allows you to write less code and do more. JavaScript ES6 brings new syntax and new awesome features to make your code more modern and more readable.
