JavaScript_Interview_QA
JavaScript_Interview_QA
A: == checks for value equality and converts types if needed. === checks for both value and type.
A: A closure is a function that remembers its outer variables even after the outer function has
finished.
Example:
function outer() {
let count = 0;
count++;
return count;
};
A: Objects can inherit properties from other objects via their prototype.
Example:
child.greet(); // 'hello'
A: The event loop handles async operations. It places them in the queue and runs them when the
A: Hoisting means variable and function declarations are moved to the top of their scope before
code runs.
A: var is function-scoped, let and const are block-scoped. const can't be reassigned.
A: 'this' refers to the object that is calling the function. Its value depends on how the function is
called.
A: Synchronous code runs in order. Asynchronous code can run later, allowing other tasks to
continue meanwhile.
Example:
A: It allows writing asynchronous code in a synchronous style using 'await' to wait for Promises.
A: null is an assigned value. undefined means a variable hasn't been assigned a value yet.
A: bind() sets the value of 'this' for a function and returns a new function.
Q: Explain the concept of event bubbling and capturing.
A: Bubbling: events go from child to parent. Capturing: from parent to child. You can choose phase
using addEventListener.
Example:
if (n <= 1) return n;
Q: What are arrow functions and how do they differ from regular functions?
A: Arrow functions don't have their own 'this' and can't be used as constructors.
A: Debouncing: delays function call until pause in input. Throttling: ensures function is called at most
A: Object.create() creates a new object with a specified prototype. Constructor uses 'new' keyword
A: It encapsulates code using IIFE or modules to avoid polluting the global scope.
Example:
A: Currying converts a function with multiple arguments into a series of functions taking one
argument each.
A: call and apply call the function immediately, bind returns a new function. apply uses array of
arguments.
A: Lexical scope means a variable's scope is defined by its position in code when it's written.