Top 100 JavaScript Interview Q&A.
Top 100 JavaScript Interview Q&A.
1. What is JavaScript?
Template literals use backticks (`) and allow embedding expressions using ${expression}.
Example: `Hello, ${name}!`.
Functions
Arrow functions provide a concise syntax for writing functions. They don’t bind their context.
o Function declaration: Defined with the function keyword. Example: function greet()
{}.
A function passed as an argument to another function and executed after the completion of
that function.
A pure function always produces the same output for the same input and has no side effects.
Closures allow a function to access variables from its outer scope even after the outer
function has been executed.
Advanced JavaScript
Promises represent a value that may be available now, in the future, or never. They can be in
one of three states: pending, fulfilled, or rejected.
It is a syntax for handling asynchronous code, making it look synchronous and easier to read.
o call: Invokes a function with a specified context and arguments passed individually.
DOM Manipulation
o getElementById()
o getElementsByClassName()
o getElementsByTagName()
o querySelector()
o querySelectorAll()
Attaching a single event listener to a parent element to manage events for child elements.
ES6+ Features
Modules allow code to be divided into reusable chunks using import and export.
Functions that can pause execution (yield) and resume later, returning an iterator.
Error Handling
Asynchronous JavaScript
• for loop
• forEach()
• map()
• for...of loop
• forEach(): Executes a function on each array element without returning a new array.
• Using Set:
• [...new Set(array)];
48. What is the difference between deep copy and shallow copy?
Miscellaneous
• Object.is(): Strict equality comparison, but considers NaN equal to itself and -0 different from
+0.
Event Handling
61. What are template literals, and how are they used?
Template literals use backticks (`) and allow embedded expressions using ${}:
• substring (start, length): Extracts part of a string based on a start index and length.
Regular Expressions
/abc/.test("abcdef"); // true
Number.isFinite(123); // true
• Number("123")
• parseInt("123")
• parseFloat("123.45")
isNaN("abc"); // true
Miscellaneous
• DOMContentLoaded: Fires when the DOM is fully loaded without waiting for assets.
document.cookie = "username=JohnDoe";
TypeScript
• Type safety
• Easier debugging
interface Person {
name: string;
age: number;
Best Practices
(function() {
console.log("IIFE");
})();
90. What is the difference between local storage, session storage, and cookies?
• call(): Invokes a function with a specified value and arguments provided one by one.
93. Generator functions, declared with function*, can pause execution using yield and resume
later.
function* generator() {
yield 1;
yield 2;
• await: Pauses the execution of an async function until a Promise is resolved or rejected.
Example:
console.log(response);
JavaScript DOM
• document.getElementById('id')
• document.querySelector('.class')
• document.getElementsByTagName('tag')
element.addEventListener('click', function() {
console.log('Clicked!');
});
JavaScript Modules
99. What is the difference between named and default exports in JavaScript modules?
Linkedin I’d:-http://linkedin.com/in/devkantbhagat
Telegram: https://t.me/Techverse_hub