Learning Objectives After completing this blog, you’ll be able to: Recognize the fat arrow syntax for functions. Describe the scope used with the this keyword. Explain why defining optional parameters in ES6+ results in cleaner code. Describe the different uses for the ‘...’ operator. The Trouble with This You’re probably familiar with defining functions like this: let result = function ( i , j ) { return i + j ; } console . log ( result ( 2 , 3 ) ) ; Copy Executing that bit of code displays 5 in the console. ES6 introduced a shorter way to define functions using what is called arrow functions. If you are coming from another language such as C#, then arrow functions will look pretty similar to something you know as lambda expressions. Using the fat arrow symbol ( => ), you can now create the same function using code like this: let result = ( i , j ) = > i + j ; console . log ( result ( 2 , 3 ) ) ; Copy All we have done here is remove the function ...
Learn and share...