Q: Can you discuss the difference between function declaration and function expression?
A: The main difference between the two is the time of which each load. If it loads before any code is executed, it is a Function Declaration. But if it loads when the interpreter reaches that line of code, it would basically be a function expression.
Another notable distinction is that function declarations are raised to the top of the other code. In contrast, function expressions are not raised. This allows the latter to retain the copies of the local variables coming from the scope from where they were defined.
Q: What is promise in JavaScript?
A: A promise is considered as in object in JavaScript, which may result to a single value within sometime in the future. It can either be a resolved value, or if not resolved, then there could be some technical reason like an occurrence of a network error.
A promise can be categorized into three possible states, namely: fulfilled, rejected, or pending. The users of promises in JavaScript can attach callbacks so that it can handle the fulfilled value or the reason for any possible rejection. As soon as the promise instructor is invoked, the promises will start doing whatever task that has been given to it.