Functions Deep Dive
mediumComplete guide with examples and interview questions · 30 min
Say it out loud in an interview — clear, simple, no textbook wording.
If an interviewer asks how functions work in JavaScript, I'd start here: a function is a reusable block of code, and there are four ways to write one — a declaration (function f() {}), an expression (const f = function() {}), an arrow (const f = () => {}), and the method shorthand (greet() {} inside an object).
The question that follows is almost always about arrows: they don't get their own this, their own arguments, or a prototype. They borrow this from wherever they were defined. That's the feature when you write .map(x => x * 2) — and the trap when you write an object method as an arrow.
One senior-level framing worth having: callable vs constructable. Regular functions are both — you can call them and new them. Arrows are callable only (new throws). Class constructors are the reverse — constructable only.
Key takeaways
- •Function declarations are hoisted and callable before their definition; expressions and arrows are not
- •Arrow functions have no own this, arguments, or prototype — use rest params instead of arguments
- •Object methods need regular functions or method shorthand; arrows as methods break this
- •Wrap implicit-return objects in parentheses: () => ({ ... })
- •Callable vs constructable: new needs a constructable function; arrows throw TypeError
Track your mastery
Sign in to save Q&A scores, coding challenge progress, points, and streaks across devices.
Sign in to save progress