In JavaScript, what code executes at runtime and what code executes at parsetime?

后端 未结 5 2080
春和景丽
春和景丽 2020-12-12 16:13

With objects especially, I don\'t understand what parts of the object run before initialization, what runs at initialization and what runs sometime after.

EDIT: It s

5条回答
  •  孤街浪徒
    2020-12-12 16:21

    Not sure what you ask exactly so I'll just share what I know.

    JavaScript functions are "pre loaded" and stored in the browser's memory which means that when you have function declared in the very end of the page and code calling it in the very beginning, it will work.

    Note that global variables, meaning any variable assigned outside of a function, are not preloaded, so can be used only after being declared.

    All commands outside of a function will be parsed in the order they appear.

    JavaScript doesn't really have "runtime", it can only respond to events or have code executed via global timers. Any other code will be parsed and "forgotten".

提交回复
热议问题