Basic JavaScript Interview Questions & Answers – Part 1
Explore 25 carefully selected JavaScript interview questions covering Core Concepts, Functions and Scope, Objects & Arrays, and Asynchronous JavaScript. This beginner-friendly guide helps you build a strong foundation and confidently tackle real-world coding interviews.
🧠 Core Concepts
- 1. What is JavaScript? JavaScript is a lightweight, interpreted programming language used to create interactive effects within web browsers.
- 2. What are the data types in JavaScript? StringNumberBooleanUndefinedNullSymbolBigIntObject
- 3. What is the difference between == and ===?== checks value only (type coercion).=== checks value and type.
- 4. What is undefined vs null?undefined : variable declared but not assigned.null : intentionally assigned empty value.
- 5. What are var, let and constvar : function-scoped.let : block-scoped.const : block-scoped and immutable reference.
- 6.What is hoisting?JavaScript's default behavior of moving declarations to the top of the scope.
- 7.What is a closure?A function that remembers variables from its lexical scope even when executed outside that scope.
- 8.What is a callback?A function passed as an argument to another function to be executed later.
- 9.What is the event loop?It handles async operations by using a queue to manage callbacks and ensures non-blocking behavior.
- 10.What is the difference between call, apply, and bind?call : calls a function with a given this and arguments.apply : same as call, but arguments are passed as an array.bind : returns a new function with bound this.
🔁 Functions and Scope
- 11. What are arrow functions?Shorter function syntax. Does not have its own this, arguments, or super.
- 12. What is lexical scope?Scope defined by the location of variable declarations in the source code.
- 13. Difference between function declaration and expression?Declarations are hoisted; expressions are not.
- 14. What is IIFE (Immediately Invoked Function Expression)?A function executed immediately after its creation:
(function() { console.log('IIFE'); })();
- 15. What is the spread operator (...)?Expands iterable elements:
let arr = [1, 2]; let newArr = [...arr, 3];
🧩 Objects & Arrays
- 16.How to clone an object?
let clone = {...original}; // shallow
- 17.What is destructuring?
let [a, b] = [1, 2]; let {name} = {name: "John"};
- 18.Difference between shallow and deep copy?Shallow: references nested objects Deep: clones everything recursively
- 19.What is this, in JS?Refers to the object that is executing the function.
- 20. What is prototype chain?Objects inherit properties from another object via __proto__.
⚙️ Asynchronous JavaScript
- 21. What is a promise? An object representing eventual completion or failure of an async operation.
- 22. What are async/await ?Syntax sugar over promises for better readability.
- 23. How to handle errors in async code?
try { await something(); } catch (e) { console.error(e); }
- 24. What is the use of setTimeout and setInterval?Delays or repeatedly executes a function after time delay.
- 25. Difference between synchronous and asynchronous? Sync: executes line-by-line
Async: continues running without waiting