JavaScript Interview Questions

Hoisting is the process via which variables and functions declared with the `var` keyword will be declared within the whole scope, even before the actual declaration. The definition will not be hoisted though, making the variable be undefined until it is defined. This behaviour is limited to the `var` keyword, `let` and *const* do not behave this way. As an example, this works:


console.log(square(5));
/* ... */
function square(n) { return n * n; }
Whereas this will fail telling you that `square is not a function`:

console.log(square(5));

var square = function(n) { 
  return n * n; 
}
Call and apply are used when a function should be called with a specific context. The context is an object that will replace the `this` keyword for this function call. Call takes the arguments for the function invocation as it's own arguments, apply takes them as a list.
Call and apply are used when a function should be called with a specific context. The context is an object that will replace the `this` keyword for this function call. Call takes the arguments for the function invocation as it's own arguments, apply takes them as a list.