When a program starts is it "Object" that is called or a "function" is called first?

An object stores functions. And functions are used to create objects.

Doesn’t it looks like chicken and egg problem?

Thinking about a Javascript compiler that stores the code and starts running it…
Where does it start from? Does it start from an object. Or does it start by calling a function?
If I say the program starts from an object, then where does that object come from? Or if I say it starts from a function. Where does this function reside, because it should reside inside an object.
For example. When I call a main ( ) in C program. This main( ) too should be residing inside some Object? But again, where did that object come from? Does this have any end?

1 Like

In terms of JavaScript, neither. A program usually starts in global scope and starts running code defined in the script that represents the start of the program. This could include 0 (user-defined) objects and 0 (user-defined) functions.

There are some objects and functions that are built-in, pre-defined and available as soon as the program starts, but they weren’t necessarily created by functions (at least not JavaScript functions). They’re supplied by the runtime which is (most likely) implemented in a lower level language such as C++.

But when it comes to running JavaScript code, there is no main() needed, just code to execute.

1 Like