Ravi Shankar Pratihast’s Post

🌱 Going back to basics In the last post, we explored how "call()", "apply()", and "bind()" can manually control what this refers to in Javascript. But what if we didn’t have to worry about "this" at all? That’s exactly where arrow functions make things simpler. The key difference between a regular function and an arrow function is this : 1. Regular functions define their own "this" (based on how they are called). 2. Arrow functions do not have their own "this", they simply inherit it from their surrounding scope. A short example : 1. regularFunction creates its own "this", so it points to user. 2. arrowFunction doesn’t! It looks outward (global scope), where "this" is undefined in "strict mode". Arrow functions simplify how we handle context by removing the need for "bind()", "call()", or "apply()", specially in modern functional code. By inheriting "this" lexically, they make context handling almost invisible!! everything just works naturally within the same scope. #JavaScript #Frontend

  • graphical user interface, text

Well put. Once you understand lexical this, a lot of JS behavior starts making sense

Like
Reply

To view or add a comment, sign in

Explore content categories