JavaScript

Skill
Programming Languages

Top 250 JavaScript Interview Questions and Answers 2025

250 questions found

Updated 16 Jan 2025

Q101. concept of Javascript used in Selenium, i.e. write value without using sendkeys in selenium.

Ans.

Javascript can be used in Selenium to execute scripts and interact with web elements. setValue() method can be used to write values without sendKeys().

  • JavascriptExecutor interface can be used to execute Javascript in Selenium

  • setValue() method can be used to set value of an input field without using sendKeys()

  • Example: JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("document.getElementById('elementId').value='value'");

Add your answer
Frequently asked in

Q102. Oops concepts of JS

Ans.

Oops concepts in JS include inheritance, encapsulation, polymorphism, and abstraction.

  • Inheritance allows objects to inherit properties and methods from a parent object.

  • Encapsulation is the practice of keeping properties and methods private to prevent external access.

  • Polymorphism allows objects to take on multiple forms and behave differently based on context.

  • Abstraction involves hiding complex implementation details and exposing only necessary information to the user.

  • Examples...read more

Add your answer

Q103. Es6 features and benefits

Ans.

ES6 (ECMAScript 2015) introduces new features like arrow functions, classes, template literals, and more.

  • Arrow functions provide a more concise syntax for writing functions.

  • Classes allow for easier object-oriented programming.

  • Template literals make it easier to work with strings by allowing interpolation and multiline strings.

  • Let and const provide block-scoped variables, reducing the risk of variable hoisting issues.

  • Destructuring allows for easily extracting values from array...read more

Add your answer
Frequently asked in

Q104. JavaScript array methods

Ans.

JavaScript array methods are built-in functions that allow you to manipulate arrays easily.

  • Some common array methods include: push(), pop(), shift(), unshift(), splice(), slice(), concat(), join(), indexOf(), includes(), filter(), map(), reduce().

  • Example: arr.push('new element') adds a new element to the end of the array.

  • Example: arr.pop() removes the last element from the array.

  • Example: arr.filter(item => item > 5) returns a new array with elements greater than 5.

Add your answer
Are these interview questions helpful?

Q105. Merge sort in js

Ans.

Merge sort is a divide and conquer algorithm that divides the input array into two halves, sorts them, and then merges the sorted halves.

  • Divide the array into two halves recursively

  • Sort each half using merge sort recursively

  • Merge the sorted halves back together

Add your answer

Q106. What is an arrey What is javascript How it works

Ans.

An array is a data structure that stores a collection of elements, typically of the same type.

  • Arrays in JavaScript are used to store multiple values in a single variable.

  • They can hold different data types, but it is common to have arrays of strings, numbers, or objects.

  • Arrays in JavaScript are zero-indexed, meaning the first element is at index 0.

  • You can access and manipulate array elements using various methods like push, pop, splice, etc.

Add your answer
Share interview questions and help millions of jobseekers 🌟

Q107. JavaScript Methods

Ans.

JavaScript methods are built-in functions that can be called on objects to perform specific tasks.

  • Methods are called using dot notation, like object.method().

  • Some common methods include toString(), toUpperCase(), and includes().

  • Methods can also be used to manipulate arrays, such as push(), pop(), and splice().

Add your answer

Q108. Generators In Javascript

Ans.

Generators in JavaScript are functions that can be paused and resumed, allowing for asynchronous programming.

  • Generators are defined using function* syntax.

  • They use the yield keyword to pause execution and return a value.

  • Generators can be iterated over using a for...of loop.

  • They are commonly used for asynchronous operations and managing state.

Add your answer
Frequently asked in

JavaScript Jobs

Business Transformation Consultant: IoT & PLM 3-7 years
IBM India Pvt. Limited
4.1
Pune
Software Developer 2-5 years
IBM India Pvt. Limited
4.1
Bangalore / Bengaluru
Automation tester 3-5 years
Robert Bosch Engineering and Business Solutions Private Limited
4.2
Hosur

Q109. Advantages of arrow function

Ans.

Arrow functions have concise syntax, implicit return, and lexical this binding.

  • Shorter syntax than traditional function expressions

  • Implicit return of a single expression

  • Lexical this binding, avoiding the need for .bind() or self = this

  • Example: const double = (num) => num * 2;

  • Example: const names = ['Alice', 'Bob', 'Charlie']; const nameLengths = names.map(name => name.length);

Add your answer
Frequently asked in

Q110. inheritence in js

Ans.

Inheritance in JavaScript allows objects to inherit properties and methods from other objects.

  • Inheritance is achieved through the use of prototypes

  • Child objects can access properties and methods of parent objects

  • Object.create() and class syntax can be used to create inheritance

  • Example: Child.prototype = Object.create(Parent.prototype)

  • Example: class Child extends Parent {}

Add your answer
Frequently asked in

Q111. Form implementation in js

Ans.

Form implementation in JS involves creating HTML forms and using JS to handle form submission and validation.

  • Create an HTML form with appropriate input fields and submit button

  • Use JS to handle form submission and prevent default behavior

  • Validate form inputs using JS and display error messages if necessary

  • Submit form data to server using AJAX or fetch API

  • Handle server response and display appropriate message to user

Add your answer

Q112. Polyfill for promise.all()

Ans.

Polyfill for promise.all() is a code that adds support for promise.all() in older browsers.

  • Polyfill can be implemented using a combination of Promise and Array.prototype.reduce()

  • The polyfill should return a promise that resolves when all promises in the input array have resolved

  • If any promise in the input array rejects, the polyfill should reject with the reason of the first promise that rejected

Add your answer

Q113. Interfaces in javascript

Ans.

Interfaces in JavaScript allow for defining a contract for objects to implement.

  • Interfaces are not natively supported in JavaScript, but can be emulated using object literals and duck typing.

  • Interfaces define a set of methods and properties that an object must implement in order to be considered an instance of that interface.

  • Interfaces can be used to enforce a certain level of consistency and structure in code, making it easier to reason about and maintain.

  • Example: defining a...read more

Add your answer

Q114. Asynchronous in JavaScript

Ans.

Asynchronous in JavaScript refers to the ability of the code to run independently of the main program flow.

  • Asynchronous functions allow other code to run while waiting for a task to complete.

  • Callbacks, Promises, and Async/Await are common ways to handle asynchronous operations in JavaScript.

  • Example: setTimeout() function in JavaScript is asynchronous, allowing other code to run while waiting for the timeout to complete.

Add your answer

Q115. set timeout qustions in js

Ans.

setTimeout function in JavaScript is used to execute a function after a specified amount of time.

  • setTimeout function takes two parameters: a function to be executed and a time delay in milliseconds

  • Example: setTimeout(function(){ console.log('Hello!'); }, 2000); will log 'Hello!' after 2 seconds

  • You can also pass additional arguments to the function being executed

Add your answer
Frequently asked in

Q116. Denouncing code in jsfiddle

Ans.

To denounce code in jsfiddle, click on the 'Share' button and select 'Embed' to get the code.

  • Click on the 'Share' button in the top menu bar.

  • Select 'Embed' from the dropdown menu.

  • Copy the code provided in the 'Embed' section and paste it where needed.

Add your answer
Frequently asked in

Q117. Conditional statements in jQuery

Ans.

Conditional statements in jQuery are used to execute different blocks of code based on specified conditions.

  • Use if statement to execute a block of code if a specified condition is true.

  • Use else statement to execute a block of code if the same condition is false.

  • Use else if statement to specify a new condition to test if the first condition is false.

Add your answer

Q118. Polyfill for Promise All,

Ans.

A polyfill is a code that adds a feature which the browser may not support. Promise.all() polyfill can be used for older browsers.

  • Create a function that takes an array of promises as input

  • Return a new promise that resolves when all promises in the input array have resolved

  • If any promise in the input array rejects, reject the new promise with the reason of the first promise that rejects

  • Use setTimeout and recursion to check if all promises have resolved

  • If the browser supports P...read more

Add your answer
Frequently asked in

Q119. Advance of JavaScript Advance of ReactJS

Ans.

JavaScript is a versatile programming language used for web development, while ReactJS is a popular JavaScript library for building user interfaces.

  • JavaScript is a high-level, interpreted language that allows for dynamic and interactive web pages.

  • It is widely supported by all major web browsers and can be used for both front-end and back-end development.

  • ReactJS is a JavaScript library developed by Facebook for building reusable UI components.

  • It uses a virtual DOM to efficient...read more

View 1 answer

Q120. Date & time in javascript

Ans.

Date & time manipulation in JavaScript

  • Use the Date object to work with dates and times in JavaScript

  • Get the current date and time using new Date()

  • Format dates using methods like toLocaleString() or toISOString()

  • Perform calculations with dates using methods like getTime() and setDate()

Add your answer

Q121. useffect using with addeventlistener

Ans.

addEventListener is used to attach an event handler to an element.

  • addEventListener is a method used to listen for a specified event on an element.

  • The 'useCapture' parameter determines the order in which event handlers are called.

  • Example: element.addEventListener('click', myFunction);

Add your answer

Q122. to-do list in vanilla javascript

Ans.

A to-do list can be created in vanilla JavaScript using DOM manipulation and event listeners.

  • Create an input field and a button for adding tasks

  • Create a container element for the tasks

  • Add event listener to the button to create a new task element and append it to the container

  • Add a checkbox to each task element to mark it as completed

  • Add a delete button to each task element to remove it from the list

  • Use local storage to save and retrieve the tasks

  • Style the to-do list using CSS

Add your answer

Q123. Event Looping in JS

Ans.

Event Looping in JS is the mechanism that allows JavaScript to handle asynchronous operations by executing callback functions in a non-blocking way.

  • Event Loop is responsible for executing code, collecting and processing events, and executing queued sub-tasks.

  • JS is single-threaded, so Event Loop helps in managing asynchronous operations without blocking the main thread.

  • Tasks are added to the call stack, then executed and removed. If a task is asynchronous, it is moved to the W...read more

Add your answer

Q124. 3. JavaScript: difference between var and let keyword, closure function

Ans.

var keyword has function scope, let keyword has block scope. Closure function is a function defined inside another function.

  • var keyword has function scope, let keyword has block scope

  • Variables declared with var are hoisted to the top of their function, let variables are not hoisted

  • Closure function is a function defined inside another function, has access to the outer function's variables

Add your answer
Frequently asked in

Q125. setTimeout api in JS

Ans.

setTimeout api in JS is used to execute a function after a specified amount of time.

  • setTimeout function takes two parameters: a function to be executed and a time delay in milliseconds

  • Example: setTimeout(function(){ console.log('Hello World!'); }, 2000) will log 'Hello World!' after 2 seconds

Add your answer

Q126. Worker threads on js

Ans.

Worker threads allow for parallel execution of JavaScript code in the browser or Node.js environment.

  • Worker threads can be used to perform CPU-intensive tasks without blocking the main thread.

  • They can also be used to communicate between different scripts or modules.

  • In Node.js, worker threads can be created using the 'worker_threads' module.

  • In the browser, worker threads can be created using the 'Worker' constructor.

  • Example use cases include image processing, data parsing, and...read more

Add your answer
Frequently asked in

Q127. Event loops in javascript

Ans.

Event loop is a mechanism in JavaScript that allows asynchronous code to be executed.

  • Event loop continuously checks the call stack and the task queue.

  • If the call stack is empty, it takes the first task from the queue and pushes it to the call stack.

  • Promises and callbacks are examples of asynchronous code that use event loop.

  • Event loop prevents blocking of the main thread and ensures smooth execution of code.

Add your answer

Q128. Design and implement MCQ platform using JavaScript

Ans.

Create a multiple choice question platform using JavaScript

  • Use HTML for the structure of the MCQ platform

  • Use CSS for styling the platform

  • Use JavaScript for functionality like selecting answers and displaying results

  • Store questions and answers in an array or object

  • Implement a scoring system to track user performance

Add your answer

Q129. Output of console.log(0 || false || "result")

Ans.

The output will be 'result'

  • The logical OR operator (||) returns the first truthy value it encounters

  • In this case, '0' is falsy, 'false' is falsy, and 'result' is truthy

  • Therefore, the output will be 'result'

Add your answer

Q130. Call backs in javascript

Ans.

Callbacks in JavaScript are functions that are passed as arguments to other functions and are executed at a later time.

  • Callbacks are commonly used in asynchronous programming to handle events or responses.

  • Callbacks can be anonymous functions or named functions.

  • Example: setTimeout(function() { console.log('Hello, world!'); }, 1000);

Add your answer

Q131. Async in javascript

Ans.

Async in JavaScript allows for non-blocking code execution, improving performance and responsiveness.

  • Async functions allow for code to run without blocking the main thread.

  • Callbacks, Promises, and async/await are common ways to handle asynchronous operations in JavaScript.

  • Example: Using setTimeout to simulate asynchronous behavior.

Add your answer

Q132. Prototypes in js

Ans.

Prototypes in JavaScript are used to add new properties or methods to existing objects.

  • Prototypes allow for inheritance in JavaScript.

  • All objects in JavaScript are linked to a prototype object.

  • Modifying the prototype object affects all instances of that object type.

Add your answer

Q133. What is Debouncing in JavaScript?

Ans.

Debouncing in JavaScript is a technique used to limit the number of times a function is called in a short period of time.

  • Debouncing is used to improve performance and prevent unnecessary function calls.

  • It delays the execution of a function until after a certain amount of time has passed since the last invocation.

  • It is commonly used in scenarios like search bars, scroll events, and input validation.

  • Debouncing can be implemented using setTimeout and clearTimeout functions.

  • Examp...read more

View 1 answer

Q134. What is html java script

Ans.

HTML is a markup language used for creating web pages, while JavaScript is a programming language used for adding interactivity to web pages.

  • HTML is used for structuring content on web pages

  • JavaScript is used for adding interactivity and dynamic behavior to web pages

  • HTML is not a programming language, but JavaScript is

  • Example: <html><head><title>Example</title></head><body><script>document.getElementById('demo').innerHTML = 'Hello World!';</script><p id='demo'></p></body></ht...read more

View 31 more answers
Frequently asked in

Q135. What is typeof operator in javascript?

Ans.

typeof operator in JavaScript returns the data type of an operand.

  • It is a unary operator.

  • It returns a string indicating the data type of the operand.

  • It can be used to check if a variable is defined or not.

  • Examples: typeof 42 returns 'number', typeof 'hello' returns 'string', typeof true returns 'boolean'.

Add your answer

Q136. Implement upload of file using Ajax?

Ans.

Ajax can be used to upload files without refreshing the page.

  • Create a form with file input and submit button.

  • Use FormData object to collect form data.

  • Send data to server using Ajax.

  • Handle file upload on server side.

  • Return response to client and update UI.

Add your answer

Q137. How to implement javascript in HTML code?

Ans.

JavaScript can be implemented in HTML code using <script> tags or by linking an external JavaScript file.

  • Use <script> tags within the <head> or <body> section of the HTML document to write JavaScript code directly in the HTML file.

  • Link an external JavaScript file using the <script> tag with the src attribute pointing to the file location.

  • Ensure that the JavaScript code is enclosed within <script> tags to indicate to the browser that it is JavaScript code.

Add your answer
Q138. React Question

What is useState() in React?

Ans.

useState() is a React hook that allows functional components to manage state.

  • useState() is used to declare a state variable in a functional component.

  • It returns an array with two elements: the current state value and a function to update the state.

  • The initial state value is passed as an argument to useState().

  • The state can be updated by calling the update function returned by useState().

  • useState() can be used multiple times in a component to manage multiple state variables.

View 1 answer

Q139. Create a profile by using css and java script

Ans.

Create a profile using CSS and JavaScript

  • Use CSS to style the profile layout

  • Use JavaScript to add interactive elements like buttons or animations

  • Include a profile picture, name, bio, and contact information

  • Add hover effects or transitions for a polished look

Add your answer
Frequently asked in

Q140. What is difference between jquery and javascript

Ans.

jQuery is a library built on top of JavaScript to simplify DOM manipulation and event handling.

  • jQuery is a JavaScript library

  • jQuery simplifies DOM manipulation and event handling

  • JavaScript is a programming language used for web development

  • JavaScript can be used for both front-end and back-end development

  • jQuery is built on top of JavaScript

Add your answer
Frequently asked in

Q141. What is the difference between a simple Js function and a generator function?

Ans.

A generator function can pause and resume execution, while a simple function cannot.

  • Generator functions use the yield keyword to pause execution and return a value

  • Generator functions can be used to create iterators

  • Simple functions execute from start to finish without pausing

  • Generator functions can improve performance by lazily computing values

  • Example of a simple function: function add(a, b) { return a + b; }

  • Example of a generator function: function* count(n) { for (let i = 0;...read more

Add your answer

Q142. what is difference between == &amp; ===? What are pipes in angular?

Ans.

Difference between == & === and pipes in Angular

  • The double equals (==) compares values after type coercion while triple equals (===) compares values without type coercion

  • Pipes in Angular are used for transforming data before displaying it in the view

  • Pipes can be used for formatting dates, numbers, and strings, as well as filtering and sorting arrays

  • Pipes can be chained together to perform multiple transformations on the same data

Add your answer

Q143. Difference between Java and Java. script

Ans.

Java is a programming language while JavaScript is a scripting language used for web development.

  • Java is a compiled language while JavaScript is an interpreted language.

  • Java is used for developing standalone applications, web applications, and Android apps while JavaScript is used for web development.

  • Java is statically typed while JavaScript is dynamically typed.

  • Java code is executed on the server-side while JavaScript code is executed on the client-side.

  • Java is more complex ...read more

Add your answer

Q144. Difference between Nodejs and Javascript.

Ans.

Node.js is a runtime environment for executing JavaScript code outside of a web browser.

  • Node.js is built on the V8 JavaScript engine, while JavaScript is a programming language.

  • Node.js allows JavaScript to be run on the server-side, while JavaScript is primarily used for client-side scripting.

  • Node.js provides additional features and APIs for server-side development, such as file system access and networking capabilities.

  • JavaScript is used for web development, creating interac...read more

View 1 answer
Frequently asked in

Q145. How promises works in JavaScript?

Ans.

Promises in JavaScript are used to handle asynchronous operations and avoid callback hell.

  • Promises represent a value that may not be available yet but will be resolved at some point in the future.

  • They have three states: pending, fulfilled, or rejected.

  • Promises can be chained using .then() and .catch() methods.

  • They can also be used with async/await syntax.

  • Example: new Promise((resolve, reject) => {...}).then(result => {...}).catch(error => {...})

Add your answer

Q146. Whats is js and ecma

Ans.

JS stands for JavaScript, a programming language used for web development. ECMAScript is a standard for scripting languages, including JavaScript.

  • JavaScript (JS) is a high-level, interpreted programming language primarily used for client-side web development.

  • ECMAScript (ES) is a standard for scripting languages, including JavaScript, to ensure interoperability between different web browsers.

  • JavaScript is based on ECMAScript standards, with different versions like ES5, ES6 (ES...read more

Add your answer

Q147. Explain arrow function

Ans.

Arrow functions are a concise way to write functions in JavaScript.

  • Arrow functions have a shorter syntax compared to traditional function expressions.

  • They do not have their own 'this' keyword, instead they inherit 'this' from the parent scope.

  • Arrow functions are best suited for non-method functions and do not work well as object methods.

Add your answer

Q148. What are the latest features of javascript ES6?

Ans.

ES6 introduced several new features to JavaScript including let and const, arrow functions, classes, and template literals.

  • let and const for block-scoped variables

  • arrow functions for concise syntax and lexical this

  • classes for object-oriented programming

  • template literals for string interpolation and multiline strings

  • destructuring for easily extracting values from arrays and objects

  • default parameters for function arguments

  • rest parameters for variable-length argument lists

  • spread...read more

Add your answer
Frequently asked in

Q149. Difference between ES6 and JavaScript?

Ans.

ES6 is a version of JavaScript with new features and syntax.

  • ES6 introduced let and const for variable declaration

  • Arrow functions were introduced in ES6

  • Template literals were introduced in ES6

  • ES6 introduced classes for object-oriented programming

  • ES6 introduced the spread operator and destructuring

  • JavaScript is the programming language, while ES6 is a version of it

Add your answer

Q150. Difference between javascript and typescript

Ans.

JavaScript is a dynamically typed language, while TypeScript is a statically typed superset of JavaScript.

  • JavaScript is dynamically typed, meaning variable types are determined at runtime.

  • TypeScript is statically typed, allowing for type checking at compile time.

  • TypeScript supports features like interfaces, enums, and type annotations that are not present in JavaScript.

  • TypeScript code needs to be transpiled to JavaScript before it can be executed in a browser.

Add your answer

Q151. Difference between map, filter in javascript

Ans.

Map and filter are array methods in JavaScript used to transform and filter array elements respectively.

  • Map creates a new array by applying a function to each element of the original array.

  • Filter creates a new array with all elements that pass the test implemented by the provided function.

  • Both methods do not modify the original array.

  • Map and filter can be chained together to perform complex transformations and filtering on arrays.

Add your answer

Q152. What is diffence between spread and rest operator

Ans.

Spread operator is used to unpack elements from an array, while rest operator is used to gather elements into an array.

  • Spread operator is denoted by three dots (...) and can be used to spread the elements of an array into individual arguments.

  • Rest operator is also denoted by three dots (...) and can be used to gather multiple elements into an array.

  • Spread operator can be used in function calls, array literals, and object literals.

  • Rest operator is commonly used in function par...read more

Add your answer

Q153. Difference between spread operator and rest operator

Ans.

Spread operator is used to split up array elements or object properties, while rest operator is used to merge multiple elements into an array.

  • Spread operator is used to expand elements in an array or object.

  • Rest operator is used to gather parameters into an array.

  • Spread operator can be used to concatenate arrays or objects.

  • Rest operator is used in function parameters to collect arguments into an array.

Add your answer

Q154. Difference between let,var,const?

Ans.

let is block scoped, var is function scoped, const is a constant variable.

  • let is block scoped, meaning it is only accessible within the block it is declared in.

  • var is function scoped, meaning it is accessible throughout the function it is declared in.

  • const is a constant variable, its value cannot be reassigned once it is initialized.

Add your answer

Q155. What is hosting in Javascript

Ans.

Hosting in JavaScript refers to the process of declaring a variable or function before it is used in the code.

  • Hosting allows you to use variables and functions before they are declared in the code.

  • Variables are hoisted to the top of their scope, while functions are fully hoisted.

  • Example: console.log(myVar); var myVar = 10; This will not throw an error because 'myVar' is hoisted to the top of the scope.

View 1 answer
Frequently asked in

Q156. In Java script how many Data types

Ans.

There are 7 data types in JavaScript: undefined, null, boolean, number, string, symbol, and object.

  • JavaScript has 6 primitive data types: undefined, null, boolean, number, string, and symbol.

  • The 7th data type is object, which includes arrays, functions, and objects themselves.

  • Each data type has its own set of values and behaviors in JavaScript.

Add your answer

Q157. How can we change the class of an element using javascript?

Ans.

You can change the class of an element using JavaScript by accessing the element and modifying its class attribute.

  • Access the element using document.getElementById(), document.getElementsByClassName(), document.querySelector(), etc.

  • Use the element's classList property to add, remove, or toggle classes.

  • Example: document.getElementById('myElement').classList.add('newClass');

Add your answer

Q158. Why is arrow function used

Ans.

Arrow functions are used for concise syntax, lexical scoping of 'this', and implicit return of single expressions.

  • Arrow functions have a more concise syntax compared to traditional function expressions.

  • Arrow functions do not bind their own 'this' value, instead they inherit 'this' from the containing scope.

  • Arrow functions automatically return the result of a single expression without needing the 'return' keyword.

Add your answer
Frequently asked in

Q159. what is JS, REACT JS

Ans.

JS is JavaScript, a programming language used for web development. React JS is a JavaScript library for building user interfaces.

  • JavaScript (JS) is a programming language commonly used for creating interactive effects within web browsers.

  • React JS is a JavaScript library developed by Facebook for building user interfaces, specifically for single-page applications.

  • React JS allows developers to create reusable UI components that can be easily managed and updated.

Add your answer

Q160. what is AJAX in javascript ?

Ans.

AJAX (Asynchronous JavaScript and XML) is a technique used in web development to create asynchronous web applications.

  • AJAX allows web pages to be updated asynchronously by exchanging data with a web server behind the scenes.

  • It enables web pages to be more responsive and interactive without the need to reload the entire page.

  • AJAX uses XMLHttpRequest object to communicate with the server and update the page dynamically.

  • Commonly used in web applications for features like auto-co...read more

Add your answer

Q161. Explain event loop on Js

Ans.

Event loop in JavaScript is a mechanism that allows for asynchronous operations to be executed in a non-blocking way.

  • Event loop is responsible for handling asynchronous operations in JavaScript.

  • It allows for tasks to be queued and executed in a non-blocking manner.

  • Event loop continuously checks the call stack and the task queue, moving tasks from the queue to the stack when the stack is empty.

  • Example: setTimeout function in JavaScript uses the event loop to execute a function...read more

Add your answer
Frequently asked in

Q162. Create a comment section with name time and comment where user can reply and the reply is nested with the comment.

Ans.

Create a nested comment section with name, time, and comment for users to reply.

  • Create a parent comment section with fields for name, time, and comment

  • Allow users to reply to comments, with nested replies

  • Display nested replies under the parent comment they are replying to

Add your answer
Frequently asked in

Q163. Any one mongo db Java script

Ans.

MongoDB JavaScript query to find documents with a specific field value

  • Use the find() method to query the collection

  • Pass in a query object with the field and value to search for

  • Example: db.collection.find({field: value})

Add your answer

Q164. Diff between JS and QP

Ans.

JS stands for JavaScript, a programming language used for web development. QP stands for Query Parser, a tool used for parsing and analyzing queries.

  • JS is a programming language used for web development.

  • QP is a tool used for parsing and analyzing queries.

  • JS is used for client-side scripting, while QP is used for query parsing and analysis.

  • Examples: JavaScript is used to create interactive web pages, while Query Parser is used in search engines to analyze user queries.

Add your answer

Q165. How to handle error in javascript

Ans.

Error handling in JavaScript involves using try-catch blocks, throwing custom errors, and using error objects.

  • Use try-catch blocks to catch and handle errors

  • Throw custom errors using the throw keyword

  • Use error objects like Error, SyntaxError, TypeError, etc. for specific types of errors

Add your answer

Q166. design for a date picker in javascript

Ans.

A date picker in JavaScript allows users to select a date from a calendar interface.

  • Use HTML input element with type 'date' for modern browsers

  • For older browsers, use a JavaScript library like jQuery UI Datepicker

  • Implement validation to ensure selected date is within acceptable range

Add your answer

Q167. hoistintg in javascript

Ans.

Hoisting in JavaScript refers to the behavior where variable and function declarations are moved to the top of their containing scope during the compilation phase.

  • Variable declarations are hoisted but not their initializations.

  • Function declarations are fully hoisted, meaning they can be called before they are declared.

  • Hoisting can lead to unexpected behavior if not understood properly.

Add your answer

Q168. 1. Coding question in JS: Capitalize last letter of each word in a string. 2. React JS: Fetch data from some given API and store data in tabular form

Ans.

Capitalize last letter of each word in a string and fetch data from API to display in tabular form using React JS.

  • Split the string into an array of words

  • Iterate through each word and capitalize the last letter

  • Join the words back together to form the modified string

  • Use React JS to fetch data from API and display in a tabular form

Add your answer
Frequently asked in

Q169. Can you provide an example of integrating R with JavaScript?

Ans.

Yes, R can be integrated with JavaScript using the 'shiny' package to create interactive web applications.

  • Use the 'shiny' package in R to create interactive web applications

  • Use the 'htmlwidgets' package to embed interactive R visualizations in web pages

  • Utilize the 'r2d3' package to create D3 visualizations in R and embed them in web applications

Add your answer

Q170. 2.Explain Polyfills

Ans.

Polyfills are code that provides modern functionality on older browsers that do not natively support it.

  • Polyfills are used to fill in the gaps in browser support for certain features or APIs.

  • They are typically implemented using JavaScript.

  • Polyfills can be used for features like Promises, Fetch API, and ES6 syntax on older browsers.

  • They help ensure that a website or application works consistently across different browsers.

Add your answer

Q171. What is javascript Dom

Ans.

JavaScript DOM stands for Document Object Model, which represents the structure of a web page as a tree of objects.

  • DOM is a programming interface for web documents.

  • It allows scripts to dynamically access and update the content, structure, and style of a web page.

  • DOM is platform and language-independent, making it a key component of web development.

  • Example: document.getElementById('myElement') allows you to access an element with a specific ID.

Add your answer

Q172. Which jscript method used to prevent form save??

Ans.

The onbeforeunload method is used to prevent form save.

  • Use the onbeforeunload method to display a warning message before leaving the page without saving the form.

  • Return a custom message in the method to prompt the user to confirm if they want to leave the page.

  • Example: window.onbeforeunload = function() { return 'Are you sure you want to leave this page without saving?'; };

Add your answer

Q173. Is IIFE irreplaceable?

Ans.

No, IIFE is not irreplaceable.

  • There are other ways to achieve the same functionality as IIFE, such as using arrow functions or block-scoped functions.

  • IIFE can also be replaced by using modules in modern JavaScript.

  • However, IIFE is still a useful tool in certain situations, such as when you need to create a private scope for your code.

Add your answer

Q174. What is currying in javascript

Ans.

Currying is a technique in functional programming where a function with multiple arguments is transformed into a sequence of nested functions, each taking a single argument.

  • Currying helps in creating reusable functions and partial application.

  • It allows for more flexible and modular code.

  • Example: const add = (a) => (b) => a + b; add(2)(3) will return 5.

Add your answer

Q175. Type of JS modules

Ans.

There are two types of JS modules: CommonJS and ES6 modules.

  • CommonJS modules use 'require' and 'module.exports' to import and export modules.

  • ES6 modules use 'import' and 'export' statements to import and export modules.

  • ES6 modules are statically analyzable, while CommonJS modules are dynamically loaded at runtime.

Add your answer

Q176. Concurrency in javascript

Ans.

Concurrency in JavaScript refers to the ability of JavaScript to execute multiple tasks simultaneously.

  • JavaScript is single-threaded, meaning it can only execute one task at a time.

  • Concurrency can be achieved in JavaScript using techniques like Web Workers, Promises, and Async/Await.

  • Web Workers allow running scripts in background threads separate from the main thread.

  • Promises help in handling asynchronous operations and executing code when the promise is resolved or rejected....read more

Add your answer

Q177. Polyfill of reduce, map

Ans.

Polyfill of reduce, map are functions that mimic the behavior of the original functions in older browsers.

  • Polyfill of reduce function can be implemented using a for loop to iterate over the array and accumulate the result.

  • Polyfill of map function can be implemented using a for loop to iterate over the array and create a new array with the transformed values.

  • These polyfills are useful for ensuring cross-browser compatibility.

  • Example of polyfill for reduce function: Array.proto...read more

Add your answer

Q178. Event Bubbling in JS

Ans.

Event bubbling is a concept in JavaScript where events triggered on a child element will also trigger on its parent elements.

  • Event bubbling is the process where an event is first captured and handled by the innermost element and then propagated to its parent elements.

  • This allows for event delegation, where a single event listener can be placed on a parent element to handle events for multiple child elements.

  • Event.stopPropagation() can be used to stop the event from bubbling u...read more

Add your answer

Q179. display use of setTimeout

Ans.

setTimeout is a function in JavaScript used to execute a function after a specified amount of time.

  • setTimeout(function, milliseconds) is used to delay the execution of a function by a specified number of milliseconds.

  • Example: setTimeout(() => { console.log('Hello, world!'); }, 2000) will log 'Hello, world!' after 2 seconds.

Add your answer
Frequently asked in

Q180. Email Validation using Javascript

Ans.

Email validation can be done using regular expressions in JavaScript.

  • Use regex to check if email is in correct format

  • Check for presence of '@' and '.' in email

  • Ensure that there are no spaces in email

  • Validate email on both client and server side

Add your answer

Q181. Form validation in js

Ans.

Form validation in JavaScript ensures that user input is correct before submitting the form.

  • Use HTML form validation attributes like 'required', 'minlength', 'maxlength', 'pattern', etc.

  • Use JavaScript to add custom validation logic like checking for valid email format or password strength.

  • Display error messages to users if validation fails to guide them on correct input.

Add your answer

Q182. Advance of javascript

Ans.

JavaScript is a versatile programming language used for creating interactive websites and web applications.

  • JavaScript is a client-side scripting language that allows for dynamic content on web pages.

  • It can be used to manipulate HTML elements, handle events, and interact with the browser.

  • JavaScript can also be used on the server-side with Node.js to build scalable and efficient applications.

  • ES6 introduced new features like arrow functions, classes, and modules to make JavaScri...read more

Add your answer

Q183. Difference between Let, Const and Var variable declarations in javascript

Ans.

Let and const are block-scoped while var is function-scoped.

  • let and const variables cannot be redeclared in the same scope

  • let and var variables can be reassigned while const variables cannot

  • var variables are hoisted to the top of their scope while let and const are not

  • let and const variables are not accessible outside their block scope

Add your answer

Q184. what is html, JavaScript

Ans.

HTML is a markup language used for creating web pages, while JavaScript is a programming language used for adding interactivity to websites.

  • HTML stands for HyperText Markup Language and is used for structuring content on web pages

  • JavaScript is a programming language that allows for dynamic content, animations, and interactive features on websites

  • HTML is used to create the structure of a webpage, while JavaScript is used to add functionality and interactivity

  • Example: <html><he...read more

Add your answer

Q185. What are the Features of Javascript.

Ans.

Javascript features include dynamic typing, event-driven programming, and object-oriented programming.

  • Dynamic typing allows for flexibility in variable types

  • Event-driven programming allows for interactive web applications

  • Object-oriented programming allows for modular and reusable code

  • Supports functional programming

  • Can manipulate HTML and CSS

  • Can handle asynchronous programming with callbacks and promises

Add your answer

Q186. How is Two way binding done?

Ans.

Two way binding is a technique used in software development to keep data synchronized between the model and the view.

  • Two way binding allows changes made to the model to be reflected in the view and vice versa.

  • It is commonly used in front-end frameworks like Angular and React.

  • In Angular, two way binding is achieved using [(ngModel)] directive.

  • In React, two way binding can be achieved using state and props.

  • Two way binding can improve user experience by reducing the need for man...read more

Add your answer

Q187. Explain about local storage

Ans.

Local storage is a web storage mechanism that allows data to be stored in the user's browser.

  • Local storage is a key-value storage system that stores data with no expiration date.

  • Data stored in local storage persists even after the browser is closed.

  • It is limited to about 5MB of data per domain.

  • Local storage is accessed using the localStorage object in JavaScript.

  • Example: localStorage.setItem('key', 'value') to store data, localStorage.getItem('key') to retrieve data.

Add your answer

Q188. What is a dynamic import in React?

Ans.

Dynamic import is a feature in React that allows loading components or modules on demand.

  • Used to improve performance by loading components only when needed

  • Implemented using the 'import()' function

  • Returns a Promise that resolves to the module

  • Can be used with React.lazy() to lazy load components

Add your answer

Q189. Create a web page with Given description

Ans.

A web page showcasing a collection of recipes with images and ingredients

  • Create a grid layout to display recipe cards

  • Include images of each recipe

  • List out ingredients for each recipe

  • Add a search bar for easy navigation

Add your answer

Q190. 8] What is jQuery??

Ans.

jQuery is a fast, small, and feature-rich JavaScript library.

  • jQuery simplifies HTML document traversing, event handling, and animating.

  • It is used to create dynamic web pages and user-friendly interfaces.

  • jQuery is cross-platform and supports a wide range of browsers.

  • It provides a simple and concise API for manipulating HTML documents.

  • Examples include selecting elements, creating animations, and handling events.

Add your answer

Q191. Explain call, apply , bind

Ans.

Call, apply, and bind are methods in JavaScript used to manipulate the context of a function.

  • Call: Invokes a function with a specified 'this' value and arguments provided individually.

  • Apply: Invokes a function with a specified 'this' value and arguments provided as an array.

  • Bind: Creates a new function that, when called, has its 'this' keyword set to a specific value.

Add your answer

Q192. What is closures in js ? Explain various types of scope in js ? Remove duplicate from an array in js ? Difference between Observable and promise in angular ?

Ans.

Closures are functions that have access to variables in their outer scope. JS has two types of scope - global and local.

  • Closures allow for data privacy and encapsulation

  • Global scope variables can be accessed from anywhere in the code

  • Local scope variables are only accessible within the function they are defined in

  • To remove duplicates from an array, use the Set object or filter method

  • Observables are used for asynchronous data streams and can emit multiple values over time

  • Promis...read more

Add your answer

Q193. Why Java and Javascript?

Ans.

Java and JavaScript are essential programming languages for web and software development.

  • Java is a versatile language used for building enterprise applications, Android apps, and server-side development.

  • JavaScript is a crucial language for front-end web development, adding interactivity to websites and web applications.

  • Both languages have a large community support, extensive libraries, and frameworks for developers to leverage.

Add your answer

Q194. What is node.js and js

Ans.

Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. JS is a scripting language used to create interactive web pages.

  • Node.js is used for server-side programming and allows for non-blocking, event-driven I/O.

  • JS is used for client-side programming and allows for dynamic and interactive web pages.

  • Both Node.js and JS are open-source and have a large community of developers.

  • Node.js can be used with various frameworks such as Express and NestJS.

  • JS can be used wit...read more

Add your answer
Q195. JavaScript Question

What are promises in javascript?

Ans.

Promises in JavaScript are objects that represent the eventual completion or failure of an asynchronous operation.

  • Promises are used to handle asynchronous operations such as fetching data from a server or reading a file.

  • They simplify the process of writing asynchronous code by providing a more structured approach.

  • Promises have three states: pending, fulfilled, or rejected.

  • They can be chained together using methods like .then() and .catch().

  • Promises help avoid callback hell an...read more

Add your answer

Q196. what is the arrow function?

Ans.

Arrow functions are a concise way to write functions in JavaScript.

  • Arrow functions were introduced in ES6.

  • They have a shorter syntax compared to traditional function expressions.

  • Arrow functions do not have their own 'this' keyword.

  • Example: const add = (a, b) => a + b;

Add your answer

Q197. What are ES 6 featurrs

Ans.

ES6 features are new functionalities added to JavaScript in ECMAScript 6 version.

  • Arrow functions for concise syntax

  • Let and const for block-scoped variables

  • Classes for object-oriented programming

  • Template literals for string interpolation

  • Destructuring for easy assignment of variables

Add your answer
Frequently asked in

Q198. features of es6 and your favorite one out of all of them

Ans.

ES6 introduced many new features like arrow functions, let and const, classes, and more. My favorite feature is template literals.

  • Template literals allow for easier string interpolation and multiline strings.

  • They use backticks (`) instead of quotes and allow for embedded expressions.

  • Example: `Hello ${name}, today is ${date}`

  • This feature improves code readability and reduces the need for concatenation.

Add your answer

Q199. What is difference between javascript and typescript

Ans.

JavaScript is a dynamic scripting language, while TypeScript is a statically typed superset of JavaScript.

  • JavaScript is dynamically typed, while TypeScript is statically typed.

  • TypeScript supports type checking at compile time, while JavaScript does not.

  • TypeScript allows for the use of interfaces and advanced OOP features, while JavaScript does not.

  • TypeScript code needs to be transpiled to JavaScript before it can be executed in a browser.

Add your answer
Frequently asked in

Q200. what is difference b/w slice and splice method

Ans.

Slice method returns a shallow copy of a portion of an array into a new array, while splice method changes the contents of an array by removing or replacing existing elements.

  • Slice method does not modify the original array, while splice method does

  • Slice method takes two arguments - start and end index, while splice method takes three arguments - start index, number of elements to remove, and optional elements to add

  • Example of slice method: let arr = [1, 2, 3, 4, 5]; let newAr...read more

Add your answer
1
2
3
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Interview experiences of popular companies

3.7
 • 10.3k Interviews
3.9
 • 8k Interviews
3.7
 • 7.5k Interviews
3.7
 • 5.5k Interviews
3.8
 • 5.5k Interviews
3.8
 • 4.8k Interviews
3.6
 • 3.8k Interviews
3.5
 • 3.7k Interviews
3.8
 • 2.8k Interviews
4.0
 • 255 Interviews
View all
JavaScript Interview Questions
Share an Interview
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
70 Lakh+

Reviews

5 Lakh+

Interviews

4 Crore+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter