JavaScript Interview Cheat Sheet
Basic JavaScript
- Data Types: String, Number, Boolean, Null, Undefined, Object, Symbol, BigInt
- var vs let vs const: var is function-scoped, let/const are block-scoped. const can't be reassigned.
- Hoisting: JS moves declarations to the top before code runs.
- == vs ===: == compares value only, === compares value and type.
- Truthy vs Falsy: Truthy (e.g., 'hello'), Falsy (e.g., '', 0, null, undefined, NaN)
Functions & Scope
- Scope: Global (outside any function), Local (inside a function), Block (inside {} blocks)
- Closures: Functions that remember variables from their outer scope.
- Callback: Function passed as argument and executed later.
- this: Refers to the object calling the function.
Functions and Objects
- Function: function greet() { [Link]('Hello'); }
- Arrow Function: const sum = (a, b) => a + b;
- Object: const obj = { key: 'value' };
- Looping: for...of for arrays, for...in for objects.
Array & String Methods
- map: returns a new array, filter: filters items, forEach: just loops.
- splice vs slice: splice modifies original, slice returns a copy.
- reduce: reduces array to a single value.
- Remove Duplicates: [...new Set(arr)]
- String Methods: split(), trim(), toUpperCase(), etc.
DOM Manipulation
- DOM: Document Object Model (structure of webpage).
- Select: getElementById(), querySelector()
- Modify: [Link], [Link]
- Events: click, input, etc.
- Create/Remove: [Link](), appendChild()
Asynchronous JavaScript
- Sync vs Async: Sync waits, Async doesn’t.
- Promises: async code with then() and catch()
- async/await: cleaner way to handle Promises
- setTimeout/setInterval: delay and repeat execution
- fetch API: used to get data from server
Misc & Coding Logic
- null vs undefined: null = empty, undefined = not assigned
- Template Literals: `Hello, ${name}`
- Shallow vs Deep Copy: shallow = one level, deep = all levels
- Reverse String: [Link]('').reverse().join('')
- Prime Check: check if number divisible by any number less than it
Bonus Concepts
- Event Delegation: handle event from parent for child elements
- Debounce/Throttle: limit how often function runs
- Memory Management: JS clears unused data automatically
- Call Stack/Event Loop: stack runs sync, loop handles async
- Storage: localStorage (forever), sessionStorage (tab only), cookies (small, with expiry)