What are the most asked JavaScript interview questions for freshers?
JavaScript fresher interviews keep circling a short list: let and const versus var, hoisting, closures, the event loop, promises and async, equality with ===, and how this behaves. Web roles add the DOM, events, and a React bridge. You do not need to recite the specification. You need to predict what a small snippet prints, then explain why. If you cannot run the snippet in your head, the definition will collapse on the next line.
The answers below are a preparation guide for freshers writing JavaScript in the browser or in a simple Node script. They are not a catalogue of every framework. React has its own page because the questions change once components and hooks appear. Start here, then open React JS interview questions if the role says React.
What is the difference between var, let, and const?
var is function-scoped, or global if you declare it outside a function. It is hoisted and can be redeclared, which is why a loop variable used to leak. let and const are block-scoped. They are hoisted into a temporal dead zone, so touching them before the line that declares them throws. const means you cannot reassign the binding. It does not freeze an object. You can still change a property of a const object. Use const by default, let when the binding must change, and leave var out of new code.
Say that last sentence in the interview before you explain the history. Then be ready for a snippet where a var inside a for loop is shared by every timeout, and a let gives each iteration its own binding. That snippet is the follow-up more often than a definition of “block.” If you can rewrite the var version with let and say what changes, you have answered the question the panel wrote the snippet for.
What is hoisting, in a sentence you can defend?
Hoisting means the declaration is known before the line runs. A function declaration can be called earlier in the same scope. A var declaration exists as undefined until the assignment. A let or const does not give you that undefined window. It throws if you touch it early. People say “the line moves to the top.” A tighter answer is that the binding is created first and the assignment stays where you wrote it. Function expressions assigned to a var are not fully available early, because the variable is hoisted and the function value arrives at the assignment.
Do not claim every function can be called from anywhere. An arrow function stored in a const is not a hoisted callable. If the interviewer writes one, walk the lines in order. That calm walk is worth more than the word hoisting.
What is a closure?
A closure is a function that remembers the variables from the place it was created, even after that outer function has returned. The practical uses are a private counter, a once-only setup, and a callback that still sees the id it was built with. The classic bug is the loop that shares one variable. The classic fix is a new binding per step, which let gives you, or a factory function that takes the value as a parameter.
Write a makeCounter that returns a function which increments a hidden number. Call it twice and say why the number survives. If you cannot write it, you do not know the answer yet. The definition “a function with its lexical environment” is acceptable only after the counter exists on the board. Interviewers have heard the definition from people who then cannot code it.
How does this work for a fresher?
this depends on how a function is called, not on where it was written, unless you used an arrow function. A method call sets this to the object before the dot. A plain call sets this to undefined in strict mode, which modules use. An arrow function does not have its own this. It uses the this of the surrounding function. That is why arrow functions are a good fit for callbacks inside a method, and a bad fit when you need a dynamic method this that changes with the caller.
bind, call, and apply set this explicitly. You rarely need them in React, and you still meet them in older browser code and in interview snippets. Know that bind returns a new function, and call invokes immediately. Losing this when you pass object.method as a callback is the bug to describe: the function is detached from the object. An arrow, or a wrapper that calls object.method(), keeps the receiver.
What is the event loop?
JavaScript runs one call stack. It does not run two of your functions at the same moment on that stack. When a timer, a network call, or a promise finishes, its callback is queued. The event loop pushes that callback onto the stack when the stack is empty. Promise reactions run before the next timer callback in the usual browser and Node ordering. You can demonstrate with a promise then, a timeout of zero, and a synchronous log. The synchronous log runs first. The promise reaction runs next. The timeout runs after that. Memorise that order by running it, not by a diagram you cannot reproduce.
This is also the answer to “is JavaScript multithreaded?” Your JavaScript code in one realm is single-threaded. The browser can do network and rendering work off that thread, and workers exist for heavier computation. A fresher who says “JavaScript is asynchronous so it runs in parallel” has mixed the queue with parallel CPU work. Asynchronous means “come back later.” Parallel means “at the same time.” The event loop is the first idea. Workers are the second, and only if you have used one or the role needs it.
How do promises and async/await fit together?
A promise is a value that will succeed or fail later. then handles success. catch handles failure. async makes a function return a promise. await pauses that function until the promise settles, and it does not freeze the whole page, because the pause gives the event loop a turn. An await without try/catch, in a context that does not handle the rejection, becomes an unhandled failure. In an interview, wrap the await if the failure is something you can tell the user about, such as a network error. Rethrow or let it travel if you cannot.
Promise.all waits for every promise and fails fast if one rejects. Promise.allSettled waits for every result even when some fail. Use all when you need all of the data. Use allSettled when a partial report is still useful. Name which one you would pick for “load three widgets, show whichever returned.” That question separates people who memorised all from people who can choose.
Do not mark a function async if you never await. Do not forget to return the promise from a then chain if a caller needs it. Both are small bugs panels still watch for.
Why does === exist?
== converts types and then compares. === compares without that conversion. "5" == 5 is true. "5" === 5 is false. null == undefined is true. null === undefined is false. Freshers lose marks by defending == as “more flexible.” In application code, flexibility here is a source of bugs. Use ===. Convert on purpose when you mean to, with Number or a clear parse, and handle the NaN case. NaN is not === to itself. Number.isNaN is the check.
Truthy and falsy values are the related trap. Empty string, 0, null, undefined, NaN, and false are falsy. An empty array is truthy. An empty object is truthy. If a condition checks a value that might be 0, a legitimate zero will look missing. Check for null or undefined explicitly when zero is real data, such as a score.
What should you say about the DOM and events?
The DOM is the browser’s tree of the page. JavaScript can find a node, read it, and change it. querySelector returns the first match. textContent sets text. innerHTML parses HTML and is a door for injection if the string includes user input, so prefer textContent unless you truly mean markup you control. Events bubble from the target up through ancestors. A listener on a parent can handle clicks from children, which is event delegation, and it stays useful when children are added later.
stopPropagation stops the bubble. preventDefault stops the browser’s built-in action, such as a form submit or a link navigation. They are different. Candidates who call one when they need the other ship a form that still submits or a menu that still closes the wrong layer. Say both names and one example each.
What is the prototype chain, briefly?
Objects can delegate property lookup to another object, their prototype. If the property is not on the object, JavaScript looks up the chain. A method on a prototype is shared, instead of copied onto every instance. Classes in modern JavaScript are syntax over this mechanism. You can write class and extends for most fresher code. You should still recognise why obj.toString exists even when you never defined it: it lives further up the chain, on Object.prototype.
The bug to mention is mutating a shared prototype, such as adding a method to Array.prototype, and then breaking a library that iterates keys. Do not patch built-in prototypes in application code. If you need a helper, write a function. That answer shows judgment, which is the point of the question once the definition is done.
How do map, filter, and reduce differ?
map returns a new array of the same length, transformed. filter returns a new array of the items that pass a test, possibly shorter. reduce folds the array into one value, which might be a number, an object, or even another array. None of them change the original array if you use them in the usual way and you do not mutate the items yourself. A fresher who uses map for a side effect, such as map that only pushes into an outside list, has chosen the wrong tool. Use forEach or a loop for side effects. Use map when you need the new array.
Be able to turn a list of orders into a total with reduce, and into a list of unpaid orders with filter. Those two snippets cover a large share of take-home questions that are really JavaScript plus a business rule. If the data is on a server, say you would filter in SQL when the table is large, and filter in JavaScript when you already hold a small page of rows. That link to SQL interview questions is a sign you know where each tool starts.
How do you present a JavaScript project?
Open one user action. A click, a submit, or a fetch. Show the function that runs, the state that changes, and the node or the JSON that updates. Name one bug: a closure that captured the wrong id, a missing await, or a === that you forgot so a string slipped through. Then say how you would test it. A project that is only a tutorial clone still works if you changed something and you can explain the change. A project you cannot run will be found out in the first “can you add a field” request.
Prepare with JavaScript training if you need a structured path, and with React JS training when the role is component work. Rehearse the spoken version before the drive. The most common interview questions page covers the “tell me about yourself” frame that sits around this technical round. Panels hire people who can do both in one afternoon.
On the day, type slowly enough to be correct. A snippet with a stray equals sign wastes the explanation you practised. Read the printed code once before you say what it logs. The event-loop order is the question people rush. Rushing is how the promise and the timeout swap places in the answer.
How do imports and modules work in an interview?
A module is a file that exports values and can import them elsewhere. In the browser and in modern Node, you use import and export. A default export is one main value. A named export is a specific function. Mixing them carelessly is how a fresher gets “does not provide an export named” on the morning of the demo. CommonJS, which is require, still appears in older Node tutorials. Know which one your project uses, and do not mix them in one file because a blog showed both. The interview point is reuse without copy-paste, and the ability to say where a function lives when they ask you to change it.
Also know that modules are strict and that top-level this is not the window. If your mental model is a single script tag and a pile of globals, say you have moved the project to modules and you no longer rely on a global function. Then open the file and show the export. That demonstration ends the question.
How do you explain fetch and JSON?
fetch starts a request and returns a promise of a response. The response is not the JSON yet. You call response.json(), which is another promise, and you check response.ok because fetch rejects on network failure and still resolves on a 404. Freshers who only await response.json() will parse an error page and then crash on a missing field. Check the status, then parse, then read the field. JSON.parse turns a string into a value. JSON.stringify turns a value into a string. A circular structure will not stringify. A date becomes a string, not a Date, when it comes back. Mention that if your UI shows a raw timestamp you did not format.
POST needs a method, a header that says the body is JSON, and a string body. Forgetting the header is the bug that makes a server see text it did not expect. Show one GET and one POST from your project. If the project has neither, say so and write a GET against a public example you understand, rather than describing a chat server you did not build.
What is the difference between null and undefined, and what does optional chaining do?
undefined usually means a variable or a property was never assigned. null means someone assigned an explicit empty. Both are falsy, and they are loosely equal to each other, which is another reason to use ===. Optional chaining, the ?. operator, reads a property and stops as null or undefined if the base is missing, instead of throwing. Nullish coalescing, ??, supplies a default only when the left side is null or undefined, not when it is 0 or an empty string. || supplies a default for every falsy value, which is wrong when zero is a real score. Pick the operator that matches the data. Say the score example. It is concrete, and it stops you from sounding like you memorised two symbols.
The follow-up snippet is often user && user.address && user.address.city rewritten with optional chaining. Write both. Then say optional chaining does not replace validation. A missing city might still be a bug you should surface, not a silent undefined on a shipping label.
A short mock you can run in the browser console
Open a blank page and the console. Declare a const object and change a property, so you remember const is not a deep freeze. Write a closure counter and call it twice. Queue a promise and a zero-delay timeout and say the order before you run it, then run it. Write a fetch shape that checks response.ok before json, even if the URL is imaginary and you only explain the branches. These four checks cover scope, closures, the event loop, and async. They take less than half an hour the day before, and they expose memorised answers that collapse when the console disagrees.
In the interview, narrate the prediction before you run or before you point at the snippet. “I expect the synchronous log, then the promise, then the timeout.” If you are wrong, correct the prediction in the next sentence. Correcting yourself is a stronger signal than defending a wrong order. If the role is React, stop this mock while the language answers are still clean, then do the component mock on the React page. Mixing both on the same tired evening produces two half answers. Split them.
A short mock you can run in the browser console
Open a blank page and the console. Declare a const object and change a property, so you remember const is not a deep freeze. Write a closure counter and call it twice. Queue a promise and a zero-delay timeout and say the order before you run it, then run it. Write a fetch shape that checks response.ok before json, even if the URL is imaginary and you only explain the branches. These four checks cover scope, closures, the event loop, and async. They take less than half an hour the day before, and they expose memorised answers that collapse when the console disagrees.
In the interview, narrate the prediction before you run or before you point at the snippet. “I expect the synchronous log, then the promise, then the timeout.” If you are wrong, correct the prediction in the next sentence. Correcting yourself is a stronger signal than defending a wrong order. If the role is React, stop this mock while the language answers are still clean, then do the component mock on the React page. Mixing both on the same tired evening produces two half answers. Split them.
Related reading: React JS interview questions, Java interview questions, Most common interview questions, SQL interview questions.
These answers are a preparation guide for students and freshers, including learners at Asmorix in Pondicherry. A company may ask a different follow-up. This page is not a leaked paper and it is not a promise of a result. Say the short answer, show one example, and revise the same day any question you could not code or click.
Frequently Asked Questions
What are the most asked JavaScript interview questions for freshers?
var versus let and const, hoisting, closures, this, the event loop, promises and async, == versus ===, DOM events, and map versus filter versus reduce.
What is a closure in JavaScript?
A function that remembers variables from the scope where it was created, even after that outer function returns. A counter that keeps its number between calls is the example to code.
What is the event loop?
JavaScript runs one call stack. Finished timers and promise reactions are queued and run when the stack is clear. Synchronous code runs first, then promise reactions, then timeouts.
What is the difference between == and ===?
== converts types before comparing. === does not. Prefer ===. null == undefined is true, and null === undefined is false.
Why does fetch need a response.ok check?
fetch rejects on network failure and still resolves on an HTTP 404. Check the status before you parse JSON, or you will treat an error page as data.
Are JavaScript and React interview questions the same?
No. React questions assume this language base and then ask about components, state, and hooks. Prepare both if the role says React.
Have a question about batches or fees?
Talk to an Asmorix counsellor in Pondicherry. Compare syllabus, timings, and placement support before you enroll.
Leave a Reply
Your email address will not be published. Required fields are marked