Top 250 JavaScript Interview Questions and Answers

Updated 28 Feb 2025

Q1. What is nodejs and difference between nodejs and javascript

Ans.

Node.js is a server-side JavaScript runtime environment.

  • Node.js is built on top of the V8 JavaScript engine from Google Chrome.

  • It allows developers to write server-side code in JavaScript.

  • Node.js has a non-blocking I/O model, making it efficient for handling large amounts of data.

  • Node.js has a vast library of modules available through npm (Node Package Manager).

View 1 answer
Frequently asked in

Q2. What is javascript in HTML

Ans.

JavaScript in HTML is a scripting language used to add interactivity and dynamic content to web pages.

  • JavaScript is a programming language that can be embedded directly into HTML code

  • It allows for interactive elements like pop-up alerts, form validation, and dynamic content updates

  • JavaScript code is typically enclosed in <script> tags within the HTML document

Add your answer

Q3. What is a class in js means? And explain its use case

Ans.

A class in JavaScript is a blueprint for creating objects with similar properties and methods.

  • Classes are used to create multiple objects with the same structure and behavior.

  • They provide a way to organize and encapsulate related data and functions.

  • Classes can have properties (variables) and methods (functions) that define their behavior.

  • Instances of a class can be created using the 'new' keyword.

  • Classes can also have constructors, which are special methods called when an obj...read more

View 1 answer
Frequently asked in

Q4. How to add style using javascript

Ans.

Styles can be added to HTML elements using JavaScript by manipulating the element's style property.

  • Access the element using document.getElementById() or document.querySelector()

  • Use the style property to set CSS styles, e.g. element.style.color = 'red'

  • Styles can also be set using CSS classes, e.g. element.classList.add('my-class')

Add your answer
Frequently asked in
Are these interview questions helpful?
Q5. 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.

Add your answer

Q6. Create dumic website

Ans.

Creating a dummy website involves designing and developing a basic website for testing purposes.

  • Choose a simple layout and design for the website

  • Include placeholder content and images

  • Ensure basic functionality like navigation and links work

  • Use dummy data for testing purposes

  • Consider using a website builder or coding from scratch

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

Q7. Difference between Local and Session Storage

Ans.

Local Storage is persistent storage that remains even after the browser is closed, while Session Storage is temporary and is cleared when the browser is closed.

  • Local Storage has no expiration date, while Session Storage is cleared when the session ends

  • Local Storage can store larger amounts of data compared to Session Storage

  • Local Storage is accessible across different browser tabs and windows, while Session Storage is limited to the current tab or window

  • Local Storage can be a...read more

View 1 answer

Q8. select all div using jquery

Ans.

Select all div using jQuery

  • Use the jQuery selector $('div') to select all div elements

  • This will return a jQuery object containing all the selected div elements

  • You can then perform operations on the selected div elements using jQuery methods

Add your answer

JavaScript Jobs

CBRE - Java Full Stack Engineer (6-10 yrs) 6-10 years
CBRE South Asia Pvt Ltd
4.2
Principal Software Engineer 14-15 years
Maersk Global Service Centres India Pvt. Ltd.
4.2
Bangalore / Bengaluru
Java Full Stack Developer 5-10 years
Robert Bosch Engineering and Business Solutions Private Limited
4.2
Hyderabad / Secunderabad

Q9. Diffrence between Normal and Arrow Fuction and its example

Ans.

Arrow functions are concise syntax for writing functions in JavaScript, compared to normal functions.

  • Arrow functions do not have their own 'this' keyword, they inherit it from the parent scope.

  • Arrow functions do not have 'arguments' object.

  • Arrow functions cannot be used as constructors.

  • Arrow functions are more concise and easier to read compared to normal functions.

Add your answer
Frequently asked in
Q10. How can you change the background color of all items in JavaScript?
Ans.

You can change the background color of all items in JavaScript by selecting all elements and setting their background color property.

  • Select all elements using document.querySelectorAll()

  • Loop through the selected elements and set their style.backgroundColor property

  • Example: document.querySelectorAll('.item').forEach(item => item.style.backgroundColor = 'blue');

Add your answer
Q11. What is the return type of the getElementsByClassName method in JavaScript?
Ans.

The return type of getElementsByClassName method in JavaScript is an array of elements.

  • The method returns an array of elements that have a specified class name.

  • The elements are returned in the order they appear in the document.

  • If no elements are found with the specified class name, an empty array is returned.

View 3 more answers

Q12. 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

Q13. Difference between Let, Const and Var. Write code and explain.

Ans.

Let, Const, and Var are used to declare variables in JavaScript with different scoping and reassignment abilities.

  • Var has function scope and can be redeclared and reassigned.

  • Let has block scope and can be reassigned but not redeclared.

  • Const has block scope and cannot be reassigned or redeclared.

View 1 answer

Q14. Difference between map and forEach method?

Ans.

map returns a new array with modified elements, forEach executes a function for each element in an array.

  • map returns a new array, forEach does not

  • map modifies the elements of the array, forEach does not

  • map returns the same number of elements as the original array, forEach does not necessarily

  • forEach is used for side effects, map is used for transformation

Add your answer
Frequently asked in

Q15. 4] What are new features of ES6?

Ans.

ES6 introduces new syntax and features to JavaScript.

  • Arrow functions

  • Template literals

  • Let and const keywords

  • Destructuring assignment

  • Default parameters

  • Rest and spread operators

  • Classes

  • Modules

Add your answer

Q16. Create a tab section using javascript

Ans.

Create a tab section using JavaScript

  • Use HTML and CSS to create the tab structure

  • Use JavaScript to handle the tab functionality

  • Add event listeners to the tab elements to switch between tabs

Add your answer

Q17. 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

Q18. What is hosting in js

Ans.

Hosting in JavaScript refers to the process of deploying a website or web application on a server to make it accessible on the internet.

  • Hosting allows users to access your website by typing in the domain name in a web browser.

  • Common hosting services include shared hosting, VPS hosting, and cloud hosting.

  • Examples of popular hosting providers include Bluehost, HostGator, and AWS.

  • Hosting also involves managing server resources, security, and performance optimization.

Add your answer

Q19. what are web workers?

Ans.

Web workers are JavaScript scripts that run in the background, separate from the main browser thread.

  • Web workers allow for parallel execution of tasks, improving performance and responsiveness.

  • They can perform computationally intensive tasks without blocking the user interface.

  • Web workers communicate with the main thread using message passing.

  • Examples of tasks suitable for web workers include data processing, image manipulation, and complex calculations.

View 1 answer
Frequently asked in

Q20. 1)What is async/defer

Ans.

async/defer are attributes used in script tags to control the loading and execution of JavaScript files.

  • async loads the script asynchronously while the HTML document continues to load

  • defer loads the script after the HTML document has finished parsing

  • async scripts are executed as soon as they are downloaded, while defer scripts are executed in the order they appear in the HTML document

  • async is useful for non-essential scripts that don't affect the page's functionality, while d...read more

Add your answer
Frequently asked in

Q21. 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

Q22. Difference between $.post and $.ajax.

Ans.

Both $.post and $.ajax are methods in jQuery used for making AJAX requests, but $.ajax is more versatile and customizable.

  • Both $.post and $.ajax are used for making AJAX requests in jQuery.

  • $.post is a shorthand method for $.ajax with predefined settings for POST requests.

  • $.ajax is more versatile and customizable, allowing for different types of requests and more options.

  • Example: $.post('example.php', {data: 'example'}, function(response) { console.log(response); });

  • Example: $...read more

Add your answer
Q23. What are the different types of decorators in JavaScript?
Ans.

Decorators in JavaScript are functions that allow you to add new functionality to existing objects or functions.

  • Function decorators: Functions that take another function as an argument and return a new function that adds some kind of behavior.

  • Class decorators: Functions that are used to modify classes in JavaScript.

  • Method decorators: Functions that are used to modify methods within a class.

  • Property decorators: Functions that are used to modify properties within a class.

Add your answer
Frequently asked in

Q24. 2)what is event loop in js

Ans.

Event loop is a mechanism in JavaScript that handles asynchronous operations.

  • 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.

  • The task is executed and the process repeats.

  • setTimeout and setInterval functions are examples of asynchronous operations that use event loop.

Add your answer
Frequently asked in

Q25. 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

Q26. Can you connect directly to db using jscript ?

Ans.

Yes, it is possible to connect to a database using JavaScript.

  • JavaScript can connect to databases using APIs such as Web SQL, IndexedDB, and MongoDB.

  • It is also possible to use Node.js to connect to databases using JavaScript.

  • However, it is not recommended to connect to a database directly from client-side JavaScript due to security concerns.

Add your answer

Q27. How much you know about python and javascript

Ans.

I have a strong understanding of Python and JavaScript, with experience in developing AI/ML applications using both languages.

  • Proficient in Python for data manipulation, machine learning algorithms, and AI model development

  • Skilled in JavaScript for front-end development and building interactive web applications

  • Experience using Python libraries like NumPy, Pandas, Scikit-learn, TensorFlow, and Keras

  • Familiar with JavaScript frameworks like React, Angular, and Node.js

Add your answer

Q28. How to improve performance in reacf js

Ans.

Performance in React JS can be improved by optimizing rendering, reducing unnecessary re-renders, using virtualization, code splitting, and lazy loading.

  • Optimize rendering by using shouldComponentUpdate or React.memo

  • Reduce unnecessary re-renders by using PureComponent or memoization techniques

  • Use virtualization for long lists or tables to improve rendering performance

  • Implement code splitting to load only necessary code for each route or component

  • Utilize lazy loading to defer ...read more

Add your answer

Q29. Explain mostly used design patterns in JavaScript

Ans.

The mostly used design patterns in JavaScript are Module, Observer, Singleton, Factory, and Prototype.

  • Module pattern helps to keep the code organized and maintainable.

  • Observer pattern is used for event handling and notification.

  • Singleton pattern restricts the instantiation of a class to a single instance.

  • Factory pattern provides an interface for creating objects in a superclass, but allows subclasses to alter the type of objects that will be created.

  • Prototype pattern creates ...read more

Add your answer
Frequently asked in

Q30. what is js hoisting?

Ans.

JS hoisting is a mechanism where variable and function declarations are moved to the top of their scope.

  • Variable declarations are hoisted but not their values

  • Function declarations are fully hoisted

  • Let and const declarations are not hoisted

Add your answer
Frequently asked in

Q31. Which modules do you use in R to import Javascript?

Ans.

The 'V8' package in R is used to import and execute JavaScript code.

  • Use the 'V8' package in R to import and execute JavaScript code.

  • Install the 'V8' package using install.packages('V8').

  • Load the 'V8' package using library(V8).

  • Use the v8() function to create a new V8 context and execute JavaScript code.

Add your answer

Q32. What is the use of polyfills?

Ans.

Polyfills are code that allows modern browsers to support features that are not natively supported.

  • Polyfills are used to bridge the gap between modern web development and older browsers.

  • They provide a way to use new features without worrying about browser compatibility.

  • Polyfills can be used for features like CSS Grid, Fetch API, and ES6 syntax.

  • They are often included in JavaScript libraries and frameworks like React and Angular.

Add your answer

Q33. 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

Q34. 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
Q35. What is webpack?
Ans.

Webpack is a module bundler for JavaScript applications.

  • Webpack takes modules with dependencies and generates static assets representing those modules.

  • It can handle various types of assets like JavaScript, CSS, and images.

  • Webpack allows for code splitting, lazy loading, and hot module replacement.

  • Common configuration options include entry, output, loaders, and plugins.

Add your answer
Frequently asked in,

Q36. What is the significance of 'this' keyword in JS?

Ans.

The 'this' keyword in JS refers to the object that is currently executing the code.

  • The value of 'this' depends on how a function is called.

  • In a method, 'this' refers to the object that the method belongs to.

  • In a regular function, 'this' refers to the global object (window in a browser).

  • In an event handler, 'this' refers to the element that triggered the event.

  • The value of 'this' can be explicitly set using call(), apply(), or bind() methods.

View 1 answer
Q37. What is an IIFE (Immediately Invoked Function Expression) in JavaScript?
Ans.

IIFE stands for Immediately Invoked Function Expression. It is a JavaScript function that is executed as soon as it is defined.

  • IIFE is a way to create a function expression and immediately invoke it.

  • It helps in creating a private scope for variables and functions.

  • It is commonly used to avoid polluting the global namespace.

  • IIFE can be written using different syntaxes like using parentheses, function declaration, or arrow functions.

Add your answer

Q38. Explain currying in JS? sum(1)(2)(); sum(2)(4)(); All these should return sum of numbers

Ans.

Currying is a technique of transforming a function that takes multiple arguments into a sequence of functions that each take a single argument.

  • Currying is achieved by returning a function that takes the next argument until all arguments are received.

  • In JavaScript, currying is often used for partial application of functions.

  • The sum function in the example takes one argument and returns a function that takes the next argument until all arguments are received.

  • The final function ...read more

Add your answer
Frequently asked in
Q39. What is the prototype chain in JavaScript?
Ans.

Prototype chain in JavaScript is the mechanism by which objects inherit properties and methods from other objects.

  • In JavaScript, each object has a private property which holds a link to another object called its prototype.

  • If a property or method is not found on an object, JavaScript will look for it in the object's prototype, and so on up the chain.

  • This allows for inheritance in JavaScript, where objects can inherit properties and methods from their prototypes.

Add your answer
Frequently asked in
Q40. What happens when you call a function using the new keyword?
Ans.

Calling a function using the new keyword creates a new instance of the function's constructor.

  • Creates a new empty object

  • Binds 'this' to the new object

  • Adds a property to the new object called '__proto__' which points to the constructor function's prototype object

  • Returns the new object

Add your answer
Frequently asked in

Q41. How we can manage the JavaScript on page when more JavaScript are lodedd and conflict with each other

Ans.

To manage conflicting JavaScript on a page, we can use various techniques like namespacing, modularization, and event delegation.

  • Use namespacing to encapsulate code and prevent conflicts

  • Modularize code into smaller, reusable components

  • Use event delegation to handle events on dynamically loaded elements

  • Avoid global variables and use local scopes

  • Use a JavaScript module bundler like Webpack to manage dependencies

Add your answer

Q42. what is difference between java and java script

Ans.

Java is a programming language used for building applications, while JavaScript is a scripting language primarily used for web development.

  • Java is a statically typed language, while JavaScript is dynamically typed.

  • Java is compiled and runs on the Java Virtual Machine (JVM), while JavaScript is interpreted by the browser.

  • Java is used for building standalone applications, server-side applications, and Android apps, while JavaScript is mainly used for client-side web development...read more

Add your answer
Frequently asked in

Q43. Do you know SQL , JAVASCRIPT?

Ans.

Yes, I have experience with SQL and JavaScript.

  • I have strong SQL skills, including writing complex queries and stored procedures.

  • I am proficient in JavaScript for front-end development and have experience with frameworks like React and Angular.

  • I have used SQL databases like MySQL and PostgreSQL, as well as NoSQL databases like MongoDB.

  • I have developed web applications that interact with databases using SQL and JavaScript.

Add your answer
Frequently asked in

Q44. How can we connect to MongoDB using Javascript?

Ans.

To connect to MongoDB using Javascript, you can use the official MongoDB Node.js driver.

  • Install the MongoDB Node.js driver using npm: npm install mongodb

  • Require the MongoDB Node.js driver in your Javascript file: const MongoClient = require('mongodb').MongoClient

  • Connect to MongoDB using MongoClient.connect() method

  • Specify the MongoDB connection URL and database name in the connect() method

  • Access the MongoDB database and perform operations like insert, update, delete, and find

Add your answer

Q45. What are microservices in javascript

Ans.

Microservices in JavaScript are small, independent, and loosely coupled services that work together to form a larger application.

  • Microservices are designed to be modular and scalable

  • Each microservice performs a specific task and communicates with other microservices through APIs

  • They can be written in different programming languages and can run on different servers

  • Examples of microservices in JavaScript include Netflix, PayPal, and Uber

Add your answer

Q46. How we do error handling in js ?

Ans.

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

  • Use try-catch blocks to catch errors and handle them gracefully

  • Throw errors using the throw keyword to indicate when something goes wrong

  • Use error objects like Error, SyntaxError, TypeError, etc. to provide more information about the error

  • Handle asynchronous errors using promises and the .catch() method

Add your answer

Q47. What is bind in javascript and write its polyfill

Ans.

Bind creates a new function with a specified 'this' value and arguments.

  • Bind returns a new function with the same body as the original function.

  • The 'this' value of the new function is bound to the first argument passed to bind().

  • The subsequent arguments are passed as arguments to the new function.

  • Polyfill for bind() can be created using call() or apply() methods.

Add your answer
Frequently asked in

Q48. What is multithreading in Javascript?

Ans.

Multithreading is not natively supported in JavaScript, but can be achieved through Web Workers.

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

  • Web Workers allow for multithreading in JavaScript by running scripts in the background.

  • Web Workers can communicate with the main thread using message passing.

  • Examples of tasks that can benefit from multithreading include heavy computations and long-running processes.

Add your answer

Q49. What marks NodeJS different than javascript and why to use it

Ans.

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

  • NodeJS allows JavaScript to be run on the server-side, enabling backend development.

  • NodeJS has a built-in library of modules that can be easily integrated into applications.

  • NodeJS is event-driven and non-blocking, making it efficient for handling multiple requests simultaneously.

Add your answer

Q50. How to use set in javascript

Ans.

Sets in JavaScript are used to store unique values of any type.

  • Create a new set using the Set constructor

  • Add values to the set using the add() method

  • Check if a value exists in the set using the has() method

  • Remove a value from the set using the delete() method

  • Iterate over the set using the forEach() method

Add your answer

Q51. How can we handle exceptions using JS

Ans.

Exceptions in JavaScript can be handled using try-catch blocks.

  • Use try-catch blocks to catch and handle exceptions in JavaScript.

  • The try block contains the code that may throw an exception.

  • The catch block is used to handle the exception if one occurs.

  • You can also use the finally block to execute code after try and catch regardless of the result.

Add your answer

Q52. What is modules in javascript?

Ans.

Modules in JavaScript are reusable pieces of code that can be exported from one file and imported into another.

  • Modules help in organizing code into separate files for better maintainability.

  • Modules can be imported using 'import' keyword and exported using 'export' keyword.

  • Modules can be used to encapsulate code and prevent global namespace pollution.

  • CommonJS and ES6 modules are two popular module systems in JavaScript.

Add your answer

Q53. Recreate tic tac to game in plain javascript

Ans.

Recreating tic tac toe game in plain JavaScript

  • Create a 3x3 grid using HTML and CSS

  • Use JavaScript to handle player turns and check for win conditions

  • Implement a reset button to start a new game

Add your answer

Q54. What are polyfill

Ans.

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

  • Polyfills are used to fill in the gaps for browser compatibility by replicating the functionality that is missing in older browsers.

  • They are typically used for adding support for new ECMAScript features, HTML5 APIs, or CSS properties.

  • Examples of polyfills include Babel for ES6 features, fetch polyfill for the Fetch API, and HTML5 Shiv for HTML5 elements in older versions of ...read more

Add your answer

Q55. what is the method used to submit forms in javascript?

Ans.

The method used to submit forms in JavaScript is the submit() method.

  • The submit() method is called on the form element.

  • It can be triggered by a button click or programmatically.

  • Example: document.getElementById('myForm').submit();

Add your answer

Q56. What is the difference between __proto__ and prototype

Ans.

The __proto__ is a property that points to the prototype of an object, while prototype is a property of a constructor function.

  • The __proto__ property is used to access the prototype of an object.

  • The prototype property is used to add properties and methods to a constructor function.

  • The __proto__ property is deprecated and should not be used in production code.

  • Changes to the prototype of a constructor function will affect all instances of that constructor function.

Add your answer
Frequently asked in

Q57. explain js , virtual dom?

Ans.

JS is a programming language used for web development. Virtual DOM is a concept in React to improve performance.

  • JS (JavaScript) is a popular programming language used for web development.

  • Virtual DOM is a concept in React where a lightweight copy of the actual DOM is created and updated to improve performance.

  • Virtual DOM allows React to efficiently update the actual DOM by only re-rendering components that have changed.

Add your answer

Q58. create prototype in js

Ans.

Creating a prototype in JavaScript

  • Use the Object.create() method to create a prototype object

  • Add properties and methods to the prototype object

  • Use the prototype object to create new instances of an object

Add your answer

Q59. 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

Q60. What is package.json

Ans.

package.json is a configuration file used in Node.js projects to manage dependencies and scripts.

  • Contains metadata about the project such as name, version, and author

  • Lists dependencies and devDependencies required for the project

  • Allows for the creation of custom scripts to run tasks

  • Can be used to specify the main file of the project

  • Can be generated using 'npm init' command

Add your answer
Frequently asked in, ,

Q61. How do add delay for animation using jQuery?

Ans.

Use the delay() method in jQuery to add delay for animation.

  • Use the delay() method before the animation function.

  • Specify the duration of the delay in milliseconds as an argument.

  • Example: $(element).delay(1000).fadeOut();

Add your answer

Q62. explain event bubbling in js

Ans.

Event bubbling is the process where an event triggered on a child element is propagated up through its parent elements.

  • Events in JavaScript propagate through the DOM tree from the target element to the root element.

  • When an event occurs on a child element, it will also trigger the same event on its parent elements.

  • Event bubbling allows for event delegation, where a single event handler is attached to a parent element to manage events for all its children.

Add your answer

Q63. What is throttling in js ?

Ans.

Throttling in JavaScript is a technique used to control the rate at which a function is executed.

  • Throttling limits the number of times a function can be called over a specified period.

  • It is commonly used in scenarios like scroll events, resize events, and API requests to prevent performance issues.

  • Example: Debouncing a search input to limit the number of API calls made while typing.

Add your answer

Q64. 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

Q65. what is optional chaining?

Ans.

Optional chaining is a feature in JavaScript that allows you to access properties of an object without worrying about whether the object is null or undefined.

  • It uses the question mark (?) operator to check if a property exists before accessing it.

  • It can be used with both object properties and function calls.

  • It can be chained multiple times to access nested properties.

  • It was introduced in ECMAScript 2020.

Add your answer
Frequently asked in

Q66. what is the difference between async and defer

Ans.

async loads script while page continues to load, defer loads script after page has loaded

  • async loads scripts asynchronously while page continues to load

  • defer loads scripts after the page has loaded

  • async scripts may not execute in order, while defer scripts do

  • async scripts may cause rendering issues, while defer scripts do not

Add your answer
Frequently asked in

Q67. How javascript runs on servers?

Ans.

JavaScript can run on servers using server-side JavaScript platforms like Node.js.

  • JavaScript can be executed on servers using server-side JavaScript platforms like Node.js.

  • Node.js allows JavaScript to run on the server-side by providing a runtime environment.

  • Server-side JavaScript enables developers to build scalable and high-performance web applications.

  • Node.js uses the V8 JavaScript engine to execute JavaScript code on the server.

  • Server-side JavaScript can handle tasks such...read more

Add your answer
Q68. What is JSX?
Ans.

JSX is a syntax extension for JavaScript that allows you to write HTML-like code in your JavaScript files.

  • JSX stands for JavaScript XML

  • It is commonly used with React to define the structure and appearance of components

  • JSX elements are transpiled into regular JavaScript function calls

  • It allows you to write HTML-like code with JavaScript expressions embedded within curly braces

  • Example:

    Hello, {name}!

Add your answer

Q69. explain setTimeout()

Ans.

setTimeout() is a function in JavaScript that allows you to delay the execution of a function for a specified amount of time.

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

  • The function passed to setTimeout() is executed once after the specified delay

  • setTimeout() returns a unique identifier (timeout ID) that can be used to cancel the execution of the function using clearTimeout()

  • Example: setTimeout(function() { console.log('Hello, ...read more

Add your answer

Q70. How to do Email validation in javascript

Ans.

Email validation in JavaScript involves checking if the input follows the correct email format.

  • Use a regular expression to check if the email follows the correct format

  • Check for the presence of '@' symbol and at least one '.' after it

  • Validate the email using built-in JavaScript functions or libraries like 'validator.js'

Add your answer

Q71. How js works on browser

Ans.

JavaScript is a scripting language that runs on the browser to make web pages interactive and dynamic.

  • JavaScript code is embedded in HTML and executed by the browser's JavaScript engine.

  • It can manipulate the DOM to change content, style, and structure of a webpage.

  • JS can handle user interactions like form submissions, button clicks, and animations.

  • It can make asynchronous requests to fetch data from servers using AJAX.

  • JS can also store data locally in the browser using Web St...read more

Add your answer

Q72. What is callback in Javascript?

Ans.

A callback in JavaScript is a function passed as an argument to another function, to be executed later.

  • Callback functions are commonly used in asynchronous programming.

  • They allow for functions to be executed after another function has finished executing.

  • Example: setTimeout function in JavaScript takes a callback function as an argument to be executed after a specified time.

Add your answer

Q73. Create a Login form and validate email input using Vanilla JS.

Ans.

Create a Login form with email validation using Vanilla JS.

  • Create a form in HTML with input fields for email and password

  • Use JavaScript to validate the email input using regular expressions

  • Display error messages if the email input is not in the correct format

Add your answer
Frequently asked in

Q74. What is .bind() function in jquery?

Ans.

The .bind() function in jQuery is used to attach an event handler function to one or more elements.

  • It allows you to specify the event type and the function to be executed when the event occurs.

  • The .bind() function can be used to bind multiple events to the same element.

  • It can also be used to pass additional data to the event handler function.

  • The .bind() function is deprecated in jQuery version 3.0 and above. It is recommended to use the .on() function instead.

Add your answer
Frequently asked in

Q75. difference between let vs var

Ans.

let is used to declare a constant while var is used to declare a variable.

  • let is immutable while var is mutable

  • let can only be assigned once while var can be assigned multiple times

  • let is preferred over var for safety and performance reasons

Add your answer

Q76. how many document ready can be used in one js file?

Ans.

There is no limit to the number of document ready functions that can be used in a js file.

  • Multiple document ready functions can be used to ensure that all necessary elements are loaded before executing code.

  • Each document ready function should be enclosed in its own set of parentheses.

  • It is important to avoid nesting document ready functions within each other.

  • Example: $(document).ready(function() { //code }); $(document).ready(function() { //code });

Add your answer

Q77. HOW TO CREATE AN ELEMENTS IN JAVASRIPT?

Ans.

Elements in JavaScript can be created using the document.createElement() method.

  • Use document.createElement() method to create a new element

  • Specify the type of element to be created (e.g. 'div', 'p', 'span')

  • Append the newly created element to an existing element using appendChild() method

Add your answer

Q78. Create a todolist using plain javascript

Ans.

Create a todolist using plain javascript

  • Create an input field for adding tasks

  • Use an array to store the tasks

  • Display the tasks in a list on the webpage

  • Add functionality to mark tasks as completed or delete them

Add your answer
Frequently asked in
Q79. What is the Temporal Dead Zone in JavaScript?
Ans.

Temporal Dead Zone is a behavior in JavaScript where variables are not accessible before they are declared.

  • Temporal Dead Zone occurs when accessing variables before they are declared

  • Variables in the Temporal Dead Zone cannot be accessed or assigned

  • The Temporal Dead Zone is a result of JavaScript's hoisting behavior

  • Example: accessing a variable before it is declared will throw a ReferenceError

Add your answer

Q80. How clearInterval works?

Ans.

clearInterval is a method used to stop the execution of setInterval() method.

  • clearInterval() method is used to stop the execution of setInterval() method.

  • It takes the ID returned by setInterval() method as a parameter.

  • The ID is used to identify the setInterval() method to be stopped.

  • Once clearInterval() is called, the setInterval() method stops executing.

Add your answer

Q81. how to perform asynchronous tasks in javaScript

Ans.

Asynchronous tasks in JavaScript allow for non-blocking operations, improving performance and user experience.

  • Use callbacks, promises, or async/await to handle asynchronous tasks

  • Callbacks: Functions passed as arguments to be executed once the task is complete

  • Promises: Objects representing the eventual completion or failure of an asynchronous operation

  • Async/await: Syntactic sugar for promises, making asynchronous code look synchronous

  • Example: Fetching data from an API, handlin...read more

Add your answer

Q82. How to get URL params using javascript

Ans.

Use window.location.search or URLSearchParams to get URL params in JavaScript

  • Use window.location.search to get the query string portion of the URL

  • Use URLSearchParams to parse and extract individual parameters from the query string

  • Example: const params = new URLSearchParams(window.location.search); const paramValue = params.get('paramName');

Add your answer

Q83. Explain the reducer method in js using the example

Ans.

Reducer method in JavaScript is used to manage state changes in applications by taking the current state and an action as input and returning a new state.

  • Reducer function takes two parameters - the current state and an action

  • It then determines how the state should change based on the action type

  • The reducer function returns a new state based on the action type

Add your answer

Q84. 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

Q85. Fundamentals of JS and Angular.

Ans.

JS is a scripting language used for web development. Angular is a JS framework for building web applications.

  • JS is used for adding interactivity to web pages

  • JS has data types like string, number, boolean, etc.

  • Angular is a framework for building single-page applications

  • Angular uses components, services, and directives for building applications

  • Angular has features like dependency injection, routing, and forms

Add your answer

Q86. 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

Q87. 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

Q88. 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

Q89. 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

Q90. 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

Q91. 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

Q92. 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

Q93. 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

Q94. 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

Q95. 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

Q96. 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

Q97. 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

Q98. 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

Q99. 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

Q100. 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
1
2
3
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Interview experiences of popular companies

3.7
 • 10.4k Interviews
3.8
 • 8.1k Interviews
3.6
 • 7.5k Interviews
3.7
 • 5.6k Interviews
3.8
 • 5.6k Interviews
3.7
 • 4.7k Interviews
3.5
 • 3.8k Interviews
3.5
 • 3.8k Interviews
3.8
 • 2.8k Interviews
3.9
 • 261 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

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