From 0cc619cc3a6d9ec0c7bc7dc630bbd24a312af8c9 Mon Sep 17 00:00:00 2001 From: Abhas Bhattacharya Date: Mon, 3 Aug 2020 04:30:13 +0530 Subject: [PATCH] update post: Closure and this - How are variables resolved within functions? --- ckddoqwv80154xvs198jkaa5m.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ckddoqwv80154xvs198jkaa5m.md b/ckddoqwv80154xvs198jkaa5m.md index 6d57ed5..1e07d4a 100644 --- a/ckddoqwv80154xvs198jkaa5m.md +++ b/ckddoqwv80154xvs198jkaa5m.md @@ -176,7 +176,8 @@ It will finally reach global scope, which always provides a `this` value (global ### What does this explain? -1. Arrow functions don't have their own `this` value. It is taken from the closest `this`-providing scope. +A. Arrow functions don't have their own `this` value. It is taken from the closest `this`-providing scope. + ```js function outer() { const inner = () => { @@ -192,7 +193,8 @@ outer.call(obj); ``` Same logic also applies for nested arrow functions. -2. Block scopes also don't have their own `this` value. +B. Block scopes also don't have their own `this` value. + ```js { // just prints global object @@ -200,7 +202,8 @@ Same logic also applies for nested arrow functions. } ``` -3. In modules, top-level `this` is `undefined`. +C. In modules, top-level `this` is `undefined`. + ```js // Save as file.mjs and run in node. // That will run it as a module.