1
{
  function foo() { console.info('999'); }
  foo = 2
}

console.info(foo)

Vert interesting! It outputs a function instead of number, why is that ?

Jerry
  • 170
  • 8
  • `foo = 2` assigns to the binding *internal to the block*, whereas the function gets put on the `window` – CertainPerformance Mar 22 '21 at 02:01
  • @CertainPerformance foo without let/const/var should also has the same effect (attach to window.) – Jerry Mar 22 '21 at 03:37
  • The difference is that `function foo` creates a binding inside in addition to outside. Without that, the `foo = 2` creates only one binding, on the window – CertainPerformance Mar 22 '21 at 03:39
  • I don't get it. If I change the order of two lines of code, the result is different, I don't know why it's related to `binding`, can you help provide some demos plz ? – Jerry Mar 22 '21 at 03:43
  • Did you look at the canonical? That's what it's there for, it explains what's going on – CertainPerformance Mar 22 '21 at 03:43

0 Answers0