1

I am using the debugger for VS Code & in below screenshot, I would expect to see the values for variables, res and nums1. How come they are not listed under 'Closure(intersect)'? (not in the Global submenu either, as I would expect)

enter image description here

user3545063
  • 681
  • 8
  • 17
  • Probably because they aren’t variables. In the function they’re not shown, maybe because they’re optimized away or because both `res` and `nums1` are identical to the global `nums1` at this point; this isn’t quite clear. However, globally, `nums1` and `nums2` are _not_ variables at all. They’re properties on `globalThis`. See [What is the purpose of the var keyword and when should I use it (or omit it)?](/q/1470488/4642212). Use `const` to make them variables. Also just to note: `let res = nums1;` is unnecessary. Just do `return nums1.filter(`…`);`. – Sebastian Simon Jan 25 '22 at 13:15
  • I suspect it is because the local function (which is the arrow function passed to `filter()`, _not_ the `intersect()` function), doesn't use `nums1` or `res`. – Ivar Jan 25 '22 at 13:27
  • search way down in the `Global` list, `nums1` is part of the `window` object, `num2` is used in the function so must be included in the Closure – rioV8 Jan 25 '22 at 17:31
  • 1
    you have arguments with the name `nums1` and `nums2` and also global vars with these names, use different names to see where they go in the debugger – rioV8 Jan 25 '22 at 17:33

0 Answers0