In the first phase of the execution, it scans through the code line by line and assigns memory to each variable. For example, if a variable is defined as a number such as num 2 or square2, the value of that variable will be calculated by the function, and the result will be assigned to the variable. Once the function completes its work, it will destroy its execution context and then return the result.
Another thing to note about JS is that it’s single-threaded, so only one instruction can be executed at a time. For this reason, it’s not recommended to use a large amount of complex and synchronous code in a webpage or app. This can cause the app to become slow and unresponsive. Instead, it’s best to use asynchronous code when possible. This will prevent the app from becoming sluggish and will allow users to interact with the site faster.