JavaScript Interview Questions for 0–1 Year Experience - Interview Questions and Answers
Modules allow code to be organized into reusable components using export
and import
. They help manage dependencies and scope.
Named exports allow exporting multiple values: export const a = 1;
. Default export uses export default function() {}
and can be imported without braces.
import()
syntax loads modules dynamically at runtime, returning a Promise: import('./module.js').then(mod => { … })
.
A build optimization that removes unused code in modules when using ES6 imports/exports and supported by bundlers like Webpack.
Functions can specify defaults: function add(a = 0, b = 0) { return a + b; }
, saving manual checks for undefined.
They support multi-line strings and tagged templates for advanced processing of literal values.
If variable and property names match, you can write const obj = { a, b }
instead of a: a, b: b
.
You can define object keys dynamically:
const prop = 'name';
const obj = { [prop]: 'Alice' };
Using shorthand method syntax:
const obj = {
greet() { console.log('Hi'); }
};
You can provide defaults: const [a = 1, b = 2] = arr;
.
class MyClass { constructor(a) { this.a = a } method() { … } }
.
Using extends
and super
:
class Child extends Parent {
constructor() {
super();
}
}
Defined on the class itself, not on instances:
class My { static greet() { … } }
Using #
syntax:
class Counter { #count = 0; }
class Person {
get name() { return this._name; }
set name(val) { this._name = val; }
}
It can create unexpected bugs and performance issues; prefer using classes.
constructor() { this.method = this.method.bind(this); }
A way to compose behaviors by copying methods into a class prototype.
Using instanceof
:
obj instanceof MyClass;
Yes, e.g.: const MyClass = class { … };
.
Transforming a function with multiple arguments into nested functions taking one argument each.
Caching results of function calls to improve performance on repeated inputs.
Creating a function with some arguments preset using Function.prototype.bind
or custom wrappers.
Returns a version of the function that delays execution until after a specified wait period.
Ensures a function is called at most once in a set interval.
Syntax function sum(...nums) {}
collects trailing arguments into an array.
No, arrow functions cannot be used with new
.
An array-like object of passed arguments in normal functions, not available in arrow functions.
A function expression with a name for recursion or debugging:
const fn = function factorial(n) { … };
fn.constructor.name === 'AsyncFunction'
or checking fn[Symbol.toStringTag]
.
Promise.all
, allSettled
, race
, any
.
Waits for all input promises to resolve or rejects at first rejection.
Resolves or rejects when the first input promise does.
allSettled
waits for all promises regardless of rejection; all
fails fast on rejection.
Resolves when any input promise resolves; rejects only if all reject.
Return a new value or promise in .then
, leading to sequential behavior.
Use try { await ... } catch(err) { … } finally { … }
.
Yes: (async () => { … })();
.
Pauses execution until the Promise resolves or rejects.
They can lead to silent failures and harder debugging; always use catch
.
Executes one task from the call stack, then checks microtasks, then repaints, then macrotasks.
A data structure that tracks execution frames for function invocations.
Holds tasks like setTimeout
, setInterval
, and I/O callbacks.
Holds Promise callbacks and queueMicrotask
, executed before macrotasks.
Both schedule microtasks, but process.nextTick
is Node-specific and runs before queueMicrotask
.
Not directly; operations are single-threaded but Web Workers or worker_threads
enable parallel tasks in browsers/Node.js.
Browser threads for heavy computation, communicating via message passing.
FIFO order for tasks added by timers, DOM events, etc.
setImmediate
runs before I/O events in Node.js; setTimeout(fn, 0)
schedules a macrotask after minimum delay.
You cannot completely; async/await
makes code appear synchronous, but operations still yield control.
node.cloneNode(deep)
creates a copy; deep=true
clones children too.
Events trigger from the root down to the target before bubbling.
el.addEventListener('click', handler, { once: true });
element.matches('.class')
.
element.closest(selector)
returns the nearest ancestor including itself.
Similar to textContent
, but respects rendered appearance and CSS.
Use element.insertAdjacentHTML(position, htmlString)
.
Use MutationObserver
, which watches for additions, removals, or attribute changes.
Schedules a callback to run before the next repaint, ideal for smooth animations.
Efficiently detects when elements enter or leave the viewport; useful for lazy-loading.
Call event.preventDefault()
in submit
handler.
Use new FormData(form)
to create key/value pairs of form fields.
Use HTML5 validation attributes or JavaScript checks in event handlers.
Use input
or change
events depending on real-time or final change capturing.
Delays the execution until user input stops for a set interval (e.g., timings search suggestions).
form.elements['name']
returns a collection of inputs.
Set input.value = 'text'
programmatically.
Use form.reset()
.
Listen for keydown
/keypress
and check event.key === 'Enter'
.
Use element.focus()
and element.blur()
.
Cookies are limited (~4KB each) and expire based on expires
; local/session storage hold more data but are domain-wide.
A low-level NoSQL database in browsers for structured data storage.
Scripts that run in the background, enabling caching, offline support, and push notifications.
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js');
}
Part of Service Workers, enabling explicit caching of resources for offline usage.
A library to use IndexedDB, WebSQL, or localStorage with a simple API.
About 5–10MB per origin; may vary by browser.
Enables reading files from user input via FileReader
.
const reader = new FileReader();
reader.onload = () => console.log(reader.result);
reader.readAsText(file);
A protocol for real-time, bidirectional communication between client and server.
Use Chrome DevTools memory snapshot and comparison of retained objects.
Use Performance tab in DevTools to record and inspect rendering, scripting, and layout times.
Dividing runtime code into chunks loaded on demand to improve initial load time.
Deferring loading of resources (like images or modules) until needed.
Use compression, proper formats, and responsive srcset
for multiple resolutions.
Batch DOM updates, use classList
, minimize layout-triggering properties.
Unreleased memory due to retained references that are no longer needed.
Use DevTools, inspect event listeners on elements to ensure removal when no longer needed.
Use <script defer>
or load scripts dynamically after initial rendering.
Metrics like LCP, CLS, and FID that measure page performance from user perspective.
A module bundler that compiles JS modules and assets into bundles for browsers.
A JavaScript compiler that transforms ES6+ code into backward-compatible JavaScript.
A tool for identifying and fixing problems in JavaScript code via static analysis.
An opinionated code formatter ensuring consistent code style.
Testing individual modules or functions in isolation to ensure correct behavior.
Jest, Mocha, Jasmine.
test('adds 1 + 2', () => {
expect(sum(1,2)).toBe(3);
});
A metric showing percentage of code exercised by tests (lines, branches).
Continuous Integration/Delivery—automated testing and deployment pipeline for code changes.
Add scripts under "scripts"
(e.g., "start": "node index.js"
) and run with npm start
.
Tutorials
Random Blogs
- SQL Joins Explained: A Complete Guide with Examples
- Datasets for Speech Recognition Analysis
- The Ultimate Guide to Starting a Career in Computer Vision
- 10 Awesome Data Science Blogs To Check Out
- Career Guide: Natural Language Processing (NLP)
- Understanding HTAP Databases: Bridging Transactions and Analytics
- AI in Marketing & Advertising: The Future of AI-Driven Strategies
- String Operations in Python
- Create Virtual Host for Nginx on Ubuntu (For Yii2 Basic & Advanced Templates)
- Robotics & AI – How AI is Powering Modern Robotics