16 | What is the map() method? | Creates a new array by calling a function on every element in the original array | const newArr = arr.map(x => x * 2); |
17 | What is the filter() method? | Creates a new array with all elements that pass a test | const filteredArr = arr.filter(x => x > 5); |
18 | What is the reduce() method? | Executes a reducer function on each element of the array, resulting in a single value | const sum = arr.reduce((acc, curr) => acc + curr, 0); |
19 | What is an arrow function? | A concise syntax for writing functions | const add = (a, b) => a + b; |
20 | What is the difference between == and ===? | == is loose equality (type coercion); === is strict equality (no type coercion) | 5 == '5' (true), 5 === '5' (false) |
21 | What is undefined? | A variable has been declared but not yet assigned a value | let x; console.log(x); // undefined |
22 | What is null? | Represents the intentional absence of any object value | let y = null; (explicitly set to null) |
23 | What is a Promise? | An object representing the eventual completion (or failure) of an asynchronous operation | new Promise((resolve, reject) => { ... }); |
24 | What is async/await? | Syntax sugar over Promises, making asynchronous code look and feel more synchronous | async function fetchData() { const response = await fetch('/api'); ... } |
25 | What is a try ...catch block? | Used for error handling in synchronous code | try { ... } catch (error) { ... } |
26 | What is a Closure? | A function that has access to variables from its outer scope, even after the outer function has finished | function outer() { let x = 10; function inner() { console.log(x); } return inner; } |
27 | What is the this keyword? | Refers to the object that owns the currently executing code (context depends on how it's called) | const obj = { method: function() { console.log(this); } }; |
28 | What is the DOM (Document Object Model)? | A tree-like structure representing HTML and XML documents | document.getElementById('myId'); |
29 | How do you select an HTML element? | Using document.getElementById(), document.querySelector(), document.querySelectorAll() | document.querySelector('.myClass'); |
30 | How do you add an event listener? | Using element.addEventListener() | button.addEventListener('click', () => { ... }); |
31 | What is JSON (JavaScript Object Notation)? | A lightweight data-interchange format | { "name": "Bob", "age": 25 } |
32 | How do you convert a JS object to a JSON string? | JSON.stringify(obj) | const jsonString = JSON.stringify(obj); |
33 | How do you convert a JSON string to a JS object? | JSON.parse(jsonString) | const obj = JSON.parse(jsonString); |
34 | What are Template Literals? | String literals using backticks (`) allowing embedded expressions | const message = Hello, ${name}!; |
35 | What is Destructuring Assignment? | Extracting values from arrays or properties from objects into distinct variables | const { name, age } = { name: 'Alice', age: 30 }; or const [a, b] = [1, 2]; |
36 | What is the Spread Syntax (... )? | Expands an iterable (like an array or string) into individual elements | const newArr = [... arr1, ... arr2];, const newObj = { ... obj1, c: 3 }; |
37 | What are Rest Parameters (... )? | Collects an indefinite number of arguments into an array | function sum(... args) { return args.reduce((a, b) => a + b, 0); } |
38 | What is a Callback Function? | A function passed as an argument to another function to be executed later | setTimeout(callback, 1000); |
39 | What is Callback Hell? | Nested callbacks that make code difficult to read and maintain | Promises offer a cleaner alternative. |
40 | What is the purpose of super? | Calls the constructor or methods of the parent class | class Child extends Parent { constructor() { super(); ... } } |
41 | What is the instanceof operator? | Checks if an object is an instance of a specific class or constructor function | if (obj instanceof Array) { ... } |
42 | What is the in operator? | Checks if a property exists in an object (either directly or in its prototype chain) | if ('name' in obj) { ... } |
43 | What is setTimeout()? | Executes a function after a specified delay | setTimeout(callback, 1000); |
44 | What is setInterval()? | Executes a function repeatedly at a specified time interval | setInterval(callback, 1000); |
45 | What is clearTimeout()? | Stops a timer created with setTimeout() | clearTimeout(timerId); |
46 | What is clearInterval()? | Stops a timer created with setInterval() | clearInterval(intervalId); |
47 | What is the difference between call(), apply(), and bind()? | All set the this value for a function. call takes arguments individually; apply takes arguments as an array; bind returns a new function with fixed this. | func.call(thisArg, arg1, arg2); func.apply(thisArg, [arg1, arg2]); const boundFunc = func.bind(thisArg); |
48 | What is a Shallow Copy? | Creates a new object/array with references to the same nested objects/arrays as the original | const newObj = { ... obj }; or const newArr = [... arr]; |
49 | What is a Deep Copy? | Creates a completely new object/array, including copies of all nested objects/arrays | JSON.parse(JSON.stringify(obj)) (simple, but has limitations) or libraries like _.cloneDeep |
50 | What is the typeof operator? | Returns a string indicating the type of the operand | typeof 'hello' ('string'), typeof 10 ('number'), typeof {} ('object'), typeof [] ('object'), typeof function(){} ('function') |