How does “scope” work with multiple script tags for Javascript in an HTML document?

前端 未结 2 691
甜味超标
甜味超标 2020-12-05 18:02

I\'m not quite sure what goes on between

2条回答
  •  心在旅途
    2020-12-05 18:56

    They are each parsed in the global context, but in order. The entire first script tag is parsed and executed before the second one is considered. As part of parsing a script, function declarations are recognized ahead of time, which is why the second one works while the first one doesn't.

提交回复
热议问题