JavaScript Interview Quizzes
193 top JavaScript interview questions sourced from greatfrontend/top-javascript-interview-questions.
- Can you offer a use case for the new arrow => function syntax?
- Describe event bubbling in JavaScript and browsers
- Describe event capturing in JavaScript and browsers
- Describe the difference between
<script>,<script async>and<script defer> - Describe the difference between a cookie,
sessionStorageandlocalStoragein browsers - Difference between document
loadevent and documentDOMContentLoadedevent? - Difference between:
function Person(){},const person = Person(), andconst person = new Person()in JavaScript? - Explain
Function.prototype.bindin JavaScript - Explain AJAX in as much detail as possible
- Explain event delegation in JavaScript
- Explain how
thisworks in JavaScript - Explain how JSONP works (and how it's not really Ajax)
- Explain how prototypal inheritance works in JavaScript
- Explain the concept of "hoisting" in JavaScript
- Explain the concept of
thisbinding in event handlers - Explain the concept of a callback function in asynchronous operations
- Explain the concept of a microtask queue
- Explain the concept of caching and how it can be used to improve performance
- Explain the concept of code coverage and how it can be used to assess test quality
- Explain the concept of Content Security Policy (CSP) and how it enhances security
- Explain the concept of Cross-Site Request Forgery (CSRF) and its mitigation techniques
- Explain the concept of debouncing and throttling
- Explain the concept of destructuring assignment for objects and arrays
- Explain the concept of error propagation in JavaScript
- Explain the concept of hoisting with regards to functions
- Explain the concept of inheritance in ES2015 classes
- Explain the concept of input validation and its importance in security
- Explain the concept of lazy loading and how it can improve performance
- Explain the concept of lexical scoping
- Explain the concept of partial application
- Explain the concept of scope in JavaScript
- Explain the concept of tagged templates
- Explain the concept of test-driven development (TDD)
- Explain the concept of the Prototype pattern
- Explain the concept of the Singleton pattern
- Explain the concept of the spread operator and its uses
- Explain the concept of the Strategy pattern
- Explain the concept of the Web Socket API
- Explain the concept of tree shaking in module bundling
- Explain the difference between
document.querySelector()anddocument.getElementById() - Explain the difference between classical inheritance and prototypal inheritance
- Explain the difference between dot notation and bracket notation for accessing object properties
- Explain the difference between global scope, function scope, and block scope
- Explain the difference between mutable and immutable objects in JavaScript
- Explain the difference between shallow copy and deep copy
- Explain the difference between synchronous and asynchronous functions in JavaScript
- Explain the difference between unit testing, integration testing, and end-to-end testing
- Explain the difference in hoisting between
var,let, andconst - Explain the differences between CommonJS modules and ES modules in JavaScript
- Explain the differences on the usage of
foobetweenfunction foo() {}andvar foo = function() {}in JavaScript - Explain the different states of a Promise
- Explain the different ways the
thiskeyword can be bound - Explain the event phases in a browser
- Explain the Observer pattern and its use cases
- Explain the same-origin policy with regards to JavaScript
- Explain what a single page app is and how to make one SEO-friendly
- Explain why the following doesn't work as an IIFE:
function foo(){}();. What needs to be changed to properly make it an IIFE? - How can closures be used to create private variables?
- How can you avoid problems related to hoisting?
- How can you create custom error objects?
- How can you implement secure authentication and authorization in JavaScript applications?
- How can you optimize DOM manipulation for better performance?
- How can you optimize network requests for better performance?
- How can you prevent clickjacking attacks?
- How can you prevent SQL injection vulnerabilities in JavaScript applications?
- How can you share code between JavaScript files?
- How can you test asynchronous code in JavaScript?
- How do
<iframe>on a page communicate? - How do
Sets andMaps handle equality checks for objects? - How do currying and partial application differ from each other?
- How do you abort a web request using
AbortControllerin JavaScript? - How do you access the index of an element in an array during iteration?
- How do you add, remove, and modify HTML elements using JavaScript?
- How do you add, remove, and update elements in an array?
- How do you check if an object has a specific property?
- How do you check the data type of a variable?
- How do you convert a
Setto an array in JavaScript? - How do you convert a string to a number in JavaScript?
- How do you create a constructor function?
- How do you detect if JavaScript is disabled on a page?
- How do you get the query string values of the current page in JavaScript?
- How do you handle errors in asynchronous operations?
- How do you handle errors using
try...catchblocks? - How do you import and export modules in JavaScript?
- How do you make an HTTP request using the Fetch API?
- How do you manipulate CSS styles using JavaScript?
- How do you organize your code?
- How do you prevent the default behavior of an event?
- How do you redirect to a new page in JavaScript?
- How do you reliably determine whether an object is empty?
- How do you use
window.historyAPI? - How do you validate form elements using the Constraint Validation API?
- How do you write unit tests for JavaScript code?
- How does hoisting affect function declarations and expressions?
- How does JavaScript garbage collection work?
- How is
Promise.all()different fromPromise.allSettled()? - Provide some examples of how currying and partial application can be used
- What advantage is there for using the JavaScript arrow syntax for a method in a constructor?
- What are
Sets andMaps and how are they used? - What are
Symbols used for in JavaScript? - What are callback functions and how are they used?
- What are default parameters and how are they used?
- What are design patterns and why are they useful?
- What are event listeners and how are they used?
- What are iterators and generators in JavaScript and what are they used for?
- What are JavaScript object getters and setters for?
- What are JavaScript object property flags and descriptors?
- What are JavaScript polyfills for?
- What are mocks and stubs and how are they used in testing?
- What are modules and why are they useful?
- What are Progressive Web Applications (PWAs)?
- What are Promises and how do they work?
- What are proxies in JavaScript used for?
- What are rest parameters and how are they used?
- What are server-sent events?
- What are some best practices for handling sensitive data in JavaScript?
- What are some best practices for writing maintainable and effective tests in JavaScript?
- What are some common performance bottlenecks in JavaScript applications?
- What are some common security headers and their purpose?
- What are some of the advantages and disadvantages of using TypeScript and compile-to-JavaScript languages
- What are some popular JavaScript testing frameworks?
- What are some techniques for reducing reflows and repaints?
- What are some tools and techniques for identifying security vulnerabilities in JavaScript code?
- What are some tools that can be used for JavaScript testing?
- What are some tools that can be used to measure and analyze JavaScript performance?
- What are template literals and how are they used?
- What are the advantages and disadvantages of using AJAX?
- What are the advantages of using the spread operator with arrays and objects?
- What are the benefits of using a module bundler?
- What are the benefits of using currying and partial application?
- What are the benefits of using spread syntax in JavaScript and how is it different from rest syntax?
- What are the common pitfalls of using the
thiskeyword? - What are the differences between
Map/SetandWeakMap/WeakSetin JavaScript? - What are the differences between
XMLHttpRequestandfetch()in JavaScript and browsers? - What are the differences between JavaScript ES2015 classes and ES5 function constructors?
- What are the differences between JavaScript variables created using
let,varorconst? - What are the different methods for iterating over an array?
- What are the different types of errors in JavaScript?
- What are the different types of testing in software development?
- What are the different ways to copy an object or an array?
- What are the different ways to make an API call in JavaScript?
- What are the metadata fields of a module?
- What are the potential issues caused by hoisting?
- What are the potential pitfalls of using closures?
- What are the pros and cons of using Promises instead of callbacks in JavaScript?
- What are the various data types in JavaScript?
- What are the various ways to create objects in JavaScript?
- What are Web Workers and how can they be used to improve performance?
- What are workers in JavaScript used for?
- What do you think of CommonJS vs ESM?
- What is
'use strict';(strict mode) in JavaScript for? - What is
Object.freeze()for? - What is
Object.preventExtensions()for? - What is
Object.seal()for? - What is a closure in JavaScript, and how/why would you use one?
- What is async/await and how does it simplify asynchronous code?
- What is Cross-Site Scripting (XSS) and how can you prevent it?
- What is currying and how does it work?
- What is recursion and how is it used in JavaScript?
- What is the
Intlnamespace object for? - What is the Command pattern and how is it used?
- What is the Decorator pattern and how is it used?
- What is the definition of a higher-order function in JavaScript?
- What is the difference between
==and===in JavaScript? - What is the difference between
event.preventDefault()andevent.stopPropagation()? - What is the difference between
innerHTMLandtextContent? - What is the difference between
mouseenterandmouseoverevent in JavaScript and browsers? - What is the difference between
setTimeout(),setImmediate(), andprocess.nextTick()? - What is the difference between a
Mapobject and a plain object in JavaScript? - What is the difference between a parameter and an argument?
- What is the difference between the Window object and the Document object?
- What is the DOM and how is it structured?
- What is the event loop in JavaScript runtimes?
- What is the Factory pattern and how is it used?
- What is the Module pattern and how does it help with encapsulation?
- What is the prototype chain and how does it work?
- What is the purpose of the
breakandcontinuestatements? - What is the purpose of the
finallyblock? - What is the purpose of the
newkeyword? - What is the purpose of the
switchstatement? - What is the spread operator and how is it used?
- What is the ternary operator and how is it used?
- What is the use of
Promise.all() - What language constructs do you use for iterating over object properties and array items in JavaScript?
- What tools and techniques do you use for debugging JavaScript code?
- What's a typical use case for anonymous functions in JavaScript?
- What's the difference between
.calland.applyin JavaScript? - What's the difference between a JavaScript variable that is:
null,undefinedor undeclared? - What's the difference between an "attribute" and a "property" in the DOM?
- When would you use
document.write()? - Why is extending built-in JavaScript objects not a good idea?
- Why is it, in general, a good idea to leave the global JavaScript scope of a website as-is and never touch it?
- Why might you want to create static class members in JavaScript?