In its simple terms, destructuring is the process of adding values to an object or array to an existing variable more straightforward. Destructuringĭestructuring sounds scary and complex. As a result the value 0 is returned and even better - no compiler error. This is an interesting (but somewhat useless) example where I am using "addSomeNumbers()" function without passing any parameters. Condensed ES6 arrow function with default parameters.Ĭonst addSomeNumbers = (a=0, b=0) => a + b Lets expand our "addSomeNumbers()" function from our last section to use default parameters. This is great, since you have more flexibilty in using a function over a wider variety of circumstances without the worry of compiler errors if you haven't satisfied all function parameters. When developing using server-side languages, such as C# you have the ability to set default values on the parameters used for your functions. But we can condense out arrow function further: // Condensed ES6 arrow function. The traditional and ES6 way can still be used in the same way to achieve our desired output. The traditional way we are all familiar with: // The "old school" way. You'll see with arrow functions, you'll have the option to condense a function that consists of many lines all the way down to single line. Arrow FunctionsĪrrow functions are beautiful and so easy on the eye when scrolling through vast amounts of code. That in itself shows how far ES6 has pushed the boundaries. If you are familiar with server-side development, you might notice some similarities from a syntax perspective. I have only scratched the surface to what ES6 has to offer and will continue to add more to the list as I learn. JavaScript has gone on a diet and cut the fat. After having the opportunity to work on React and React Native projects, I had a chance in putting my new found ES6 knowledge to good use! ES6 is filled to the brim with some really nice improvements that make JavaScript development much more concise and efficient. I've been doing some personal research into improving my own JavaScript development. I decided to get more familiar with the new version of JavaScript - ES6.
0 Comments
Leave a Reply. |