Today, we will discuss about some essential ES6 features used in React JS. ES6 stands for ECMAScript6 which is like a standard used in writing JS (JavaScript) code. From the past years, ES6 has been updating to better standards thus the reason why we have different versions like ECMAScript5 ... and today we are working with version 6 which is the most stable and widely used version now at the time of writing this article.
So you see, it will be kind-of challenging for a modern developer to ignore such changes because it affects him or her.
In React JS, there are some implementations of these ES6 features which we are going to look at. But we will implement them to see how they work in a HTML document.
Variables
ES6 implemented an unusual way of creating a variable using the const keyword. Though we also have the let, I will focus on explaining about the const.
Creating a variable with the keyword const, makes the variable immutable, meaning it’s value can not be changed. For example ;
const x = 5; is constant
Changing that value elsewhere in the same scope will cause an error or will not work like in the case below.
index.html
Thus, take note of how you use constants in React JS.
ES6 Functions
The modifications in ES function are very useful in React JS and applicable or implemented in most cases. We have the ES6 Arrow function and Classes.
Arrow function:
Arrow functions isn’t obliged to have the return, function keyword and curly braces.
var name = (x, y) => x * y;
Classes:
Constructors store class properties and be used by declaring class.property. For example; me.Id as seen below outputs the name that will be passed as argument.
class me {
constructor(name) {this.Id = name;}}
Have you understood?
You can always ask your questions or drop comments below.
Thanks.
Comments
Post a Comment
Please do not enter any spam link in the comment box.