Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
November 28, 2021 04:48 pm GMT

4 Latest Javascript Features...

JavaScript has grown way beyond the browser. Code School's Sergio Cruz reveals the new features, tools and libraries that are transforming the way we use JavaScript today

1 - WRITE TOMORROW'S I JAVASCRIPT TODAY WITH BABEL

Not all browsers understand ES2015 code yet, so in order to use the latest features of the language today, we need a tool like Babel. This transforms ES2o15 code into ES5 JavaScript code that all browsers are able to interpret. It is common for developers to include Babel in their deployment process through build systems such as gulp or webpack. This approach allows devs to use the latest tech while ensuring their apps remain compatible with old browser versions, but only at the deployment stage.

2 - EXPLORE NEW WAYS OF ' DECLARING VARIABLES

In ES2o15, JavaScript introduced two new ways of declaring variables: let and const . let is used when a variable will be reassigned, whereas const keeps a variable from being reassigned. Note that using const does not freeze arrays and objects, and it doesn't stop properties from being mutated. Instead, it just keeps the variable itself from being reassigned.
The main benefit that both let and const deliver over var is that when using var , your variables get scoped to the top of the current function, therefore making the variable available to the whole function. In contrast, let and const are scoped to their closest block, allowing developers to declare variables within if , while , for and even switch blocks, without worrying about the variable scope leaking outside of that context.

3 - USE ARROW FUNCTIONS TO KEEP this INTACT

Another feature that's been added to JavaScript in recent years is arrow functions. These have the ability to keep the this context intact, especially when using it within callbacks that might get called from somewhere else (i.e. adding an event listener with jQuery, and so on). Essentially, arrow functions replace the need to add .bind(this) at the end of a function declaration. There are two main ways of writing arrow functions: one-liners and multiple-liners. One-liners have only one expression and return the value of that given expression, without the need for curly braces. Multiple-liners, on the other hand, have curly braces and the return keyword must be used explicitly.

4 - USE PROMISES TO AVOID A CALLBACK CAN OF WORMS

JavaScript does a lot of its operations asynchronously, so passing callback functions while waiting for other things to happen is a pretty standard pattern. The problem begins, though, when you're executing an async action that will trigger another async action, and so forth.


Original Link: https://dev.to/nikotech/4-latest-javascript-features-74a

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To