

InterviewSolution
Saved Bookmarks
1. |
Why are arrow functions used in ES6? |
Answer» <html><body><p>Arrow functions are <a href="https://interviewquestions.tuteehub.com/tag/one-241053" style="font-weight:bold;" target="_blank" title="Click to know more about ONE">ONE</a> of the major reasons for the popularity of ES6 due to the reasons mentioned below:</p><ul><li><strong>Safety of scope</strong>: Consistent use of arrow functions guarantee to use the same thisObject as the root. Using the arrow functions provides scope safety because even if a single standard function <a href="https://interviewquestions.tuteehub.com/tag/callback-412427" style="font-weight:bold;" target="_blank" title="Click to know more about CALLBACK">CALLBACK</a> is mixed with some arrow functions, the probability of scope getting disturb increases.</li><li><strong>Compactness</strong>: It is easier to read and write when it comes to arrow functions as compared to other functions. This provides a less <a href="https://interviewquestions.tuteehub.com/tag/complex-926309" style="font-weight:bold;" target="_blank" title="Click to know more about COMPLEX">COMPLEX</a> approach of using ES6 as well as the arrow functions.</li><li><strong>Provides clarity</strong>: A developer can easily identify what “ thisObject” is and find out the next-higher function statement after the arrow function statement if he/she uses arrow function in most of the <a href="https://interviewquestions.tuteehub.com/tag/program-246414" style="font-weight:bold;" target="_blank" title="Click to know more about PROGRAM">PROGRAM</a>. It will provide <a href="https://interviewquestions.tuteehub.com/tag/huge-1032540" style="font-weight:bold;" target="_blank" title="Click to know more about HUGE">HUGE</a> clarity and easy detection of errors in any program.</li></ul></body></html> | |