While executing a js file, firstly a global execution context is created to execute the entire js code. Again, a main function is also get called to execute the same code.
So my question is, do the main function is called first and then the global execution context gets created or first the global execution context gets created first and then the main function gets created?
I think, first the Global Execution context gets created and then the main function gets created.
JavaScript doesn't have any "main" function concept like there is in some C or Java contexts. Once the global execution context is created, execution starts at the beginning of the code in the script you ran (more in the specification). (Assuming we're talking about a non-module script.) For example: