What is the difference between var, let and const in JavaScript?
var is function-scoped and can be redeclared; let and const are block-scoped, and const cannot be reassigned after it is set.
Frontend 路 Intern to senior
JavaScript is asked about in almost every frontend and full stack interview, and in many backend ones that use Node.js. These questions start with the fundamentals that interns and freshers are expected to know and move up to the event loop, prototypes and memory management that senior interviews probe.
20 questions
var is function-scoped and can be redeclared; let and const are block-scoped, and const cannot be reassigned after it is set.
== compares values after type coercion, while === compares both value and type with no conversion, so it is the safer default.
Hoisting is JavaScript moving declarations to the top of their scope during compilation, so functions and var variables can be referenced before the line where they are written.
undefined means a variable has been declared but no value was assigned; null is an explicit value meaning 'no value' that you assign on purpose.
map transforms every item into a new array of the same length, filter keeps only items that pass a test, and reduce folds the whole array into a single value.
Normalise the string (lower case, remove non-alphanumeric characters), then compare characters from both ends moving inward with two pointers. This is O(n) time and O(1) extra space beyond the normalised copy.
Cookies are sent to the server with every matching request and can expire; localStorage persists until cleared and stays in the browser; sessionStorage lasts for the current tab only.
Walk through the array once while storing each number鈥檚 index in a hash map; for every number, check whether target minus that number is already in the map. This runs in O(n) time and O(n) space.
A closure is a function that keeps access to the variables of the scope where it was created, even after that outer function has finished running.
this is decided by how a function is called, not where it is written: as a method it is the object before the dot, with new it is the new object, and arrow functions inherit it from the enclosing scope.
async/await is syntax built on top of promises that lets you write asynchronous code that reads like synchronous code; under the hood every async function returns a promise.
Event delegation means attaching one listener to a parent element and using event bubbling to handle events from its children, instead of adding a listener to each child.
Recursively walk the array: when an element is an array, flatten it and append the result; otherwise append the element. An iterative version uses an explicit stack to avoid recursion limits.
The event loop is the mechanism that lets single-threaded JavaScript handle asynchronous work: it runs the call stack to empty, then runs all queued microtasks (promises), then takes the next task (timers, events) from the queue.
In JavaScript every object has an internal link to another object called its prototype, and property lookups walk up this prototype chain until the property is found or the chain ends.
Debounce waits until the user stops triggering an event for a set time before running the function; throttle runs the function at most once per time interval no matter how often the event fires.
Both download the script without blocking HTML parsing. defer waits until parsing finishes and runs scripts in document order; async runs a script as soon as it is downloaded, which can be before or after parsing and in any order.
The browser parses HTML into a DOM and CSS into a CSSOM, combines them into a render tree, computes layout (reflow), paints pixels and composites layers onto the screen.
Take heap snapshots in Chrome DevTools before and after the suspect action, compare what grew, and fix the retaining reference, which is usually a forgotten listener, timer, global variable or unbounded cache.
Core Web Vitals are Google鈥檚 field metrics for real-user experience: LCP (loading), INP (interactivity) and CLS (visual stability). They influence search ranking and are measured on real devices, not only Lighthouse.