3

I wrote a small code to see how the call stack and scopes work in steps:

function foo(){
  debugger;
  bar();
  function bar(){
    thi();
    function thi(){
      var y = 20;
    }
  }
}
foo();

Here is the screen from the Firefox debugger: enter image description here

The question is what are the scopes called 'block? If we look into them, we can see that these are the scopes of 'bar' and 'thi' functions. But, why are they signed with the word "block"?

JLRishe
  • 99,490
  • 19
  • 131
  • 169
Max
  • 82
  • 7
  • 1
    What debugger are you using? It seems to be confused, as obviously in your code there are only function scopes. – Bergi Jan 17 '18 at 15:24
  • @Bergi judging from the UI, looks like firefox. – Federico klez Culloca Jan 17 '18 at 15:25
  • What line did you break at when this view is show? Doesn't appear to be the `debugger` one. Did you step manually? – Bergi Jan 17 '18 at 15:25
  • 1
    Looks like someone else asked pretty much the same question 16 days ago: https://stackoverflow.com/questions/41426956/javascript-let-block-scope-in-firefox-developer-tools-debug-view – JLRishe Jan 17 '18 at 15:27
  • @Bergi I can reproduce this if I set a breakpoint on the `var y = 20` line and take one step. It's definitely paused within the `thi` function. – JLRishe Jan 17 '18 at 15:31
  • @Bergi, I use the debugger of firefox. – Max Jan 17 '18 at 15:34
  • @JLRishe, you are right, it's paused within the thi func – Max Jan 17 '18 at 15:34
  • @JLRishe Not exactly. I could answer that one but not this here. – Bergi Jan 17 '18 at 15:39
  • 1
    Hm, `thi: (optimised away)` might give a hint on why the upper block is not a function scope, but still it should show `bar` somewhere. Unless that was inlined as well? – Bergi Jan 17 '18 at 15:41
  • Isn't that a "block scope" introduced by ES6 ? – andy Jan 17 '18 at 16:17

0 Answers0