JavaScript

Skill
Programming Language

Top 250 JavaScript Interview Questions and Answers 2024

250 questions found

Updated 16 Dec 2024

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 is a scripting language used to add interactivity to HTML pages.

  • JavaScript is embedded in HTML using the

Add your answer

Q3. what's is clouser in javascript

Ans.

A closure is a function that has access to variables in its outer (enclosing) scope.

  • A closure is created when a function is defined inside another function

  • The inner function has access to the outer function's variables and parameters

  • Closures can be used to create private variables and methods

  • Example: function outer() { var x = 10; function inner() { console.log(x); } return inner; } var closure = outer(); closure(); // Output: 10

Add your answer

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

Q6. Difference between class and functional component?

Ans.

Class components are ES6 classes that extend the React.Component class, while functional components are just plain JavaScript functions.

  • Class components are more feature-rich and have access to lifecycle methods.

  • Functional components are simpler and easier to read and test.

  • Class components can have state and use lifecycle methods like componentDidMount and componentDidUpdate.

  • Functional components are stateless and do not have lifecycle methods.

  • Functional components can be use...read more

View 2 more answers
Share interview questions and help millions of jobseekers 🌟

Q7. What is CSS and javascript

Ans.

CSS is used for styling web pages while JavaScript is used for adding interactivity and functionality.

  • CSS stands for Cascading Style Sheets and is used to style the layout and appearance of web pages.

  • JavaScript is a programming language used to add interactivity and functionality to web pages.

  • CSS can be used to change font styles, colors, and layout of web pages.

  • JavaScript can be used to create pop-up windows, validate forms, and create animations.

  • Both CSS and JavaScript are ...read more

Add your 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

Senior Developer - Java, Node.js, or JavaScript 7-9 years
SAP India Pvt.Ltd
4.2
₹ 16 L/yr - ₹ 39 L/yr
(AmbitionBox estimate)
Bangalore / Bengaluru
JavaScript Dev | Sr. Consultant 5-8 years
Deloitte
3.8
₹ 10 L/yr - ₹ 20 L/yr
Delhi/Ncr
Vue.js Developer - Javascript/TypeScript (6-9 yrs) 6-9 years
te
4.2
₹ 18 L/yr - ₹ 30 L/yr

Q9. Explain call(), apply () and bind() method?

Ans.

call(), apply() and bind() are methods used to manipulate the 'this' keyword in JavaScript.

  • call() and apply() are used to invoke a function with a specific 'this' context and arguments.

  • call() accepts arguments as a comma-separated list, while apply() accepts arguments as an array.

  • bind() returns a new function with a specific 'this' context, which can be invoked later with arguments.

  • bind() is useful for creating a new function with a fixed 'this' context, such as event handler...read more

Add your answer

Q10. what is difference between JavaScript and Angular

Ans.

JavaScript is a programming language used for web development, while Angular is a JavaScript framework for building web applications.

  • JavaScript is a programming language that allows developers to add interactivity and dynamic features to websites.

  • Angular is a JavaScript framework that provides a structure for building web applications.

  • JavaScript can be used independently to create web functionality, while Angular is built on top of JavaScript and provides additional features ...read more

View 3 more answers
Frequently asked in

Q11. Why use in java to Javascript

Ans.

Java and JavaScript are two different programming languages with different use cases.

  • Java is used for building server-side applications, Android apps, and enterprise software.

  • JavaScript is used for building interactive web applications and front-end development.

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

  • Java is statically typed while JavaScript is dynamically typed.

  • Java code runs on the Java Virtual Machine (JVM) while JavaScript code runs on web ...read more

Add your answer
Frequently asked in

Q12. 1.diffrence between javaScript and nodejs

Ans.

JavaScript is a programming language used for web development, while Node.js is a runtime environment for executing JavaScript code outside of a web browser.

  • JavaScript is primarily used for client-side scripting, while Node.js is used for server-side scripting.

  • JavaScript is executed in a web browser, while Node.js is executed on a server.

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

  • JavaSc...read more

View 1 answer

Q13. How Promise works? What is Promise.all. Write code for both.

Ans.

Promises are a way to handle asynchronous operations in JavaScript. Promise.all is used to execute multiple promises concurrently.

  • Promises represent a value that may not be available yet

  • They have three states: pending, fulfilled, and rejected

  • Promise.all takes an array of promises and returns a new promise that resolves when all promises in the array have resolved

  • If any promise in the array is rejected, the returned promise is rejected with the reason of the first promise that...read more

Add your answer

Q14. Difference between JS and ECMAScript

Ans.

ECMAScript is a standard, while JavaScript is an implementation of that standard.

  • ECMAScript is a specification for scripting languages, while JavaScript is a programming language that implements ECMAScript.

  • ECMAScript is maintained by ECMA International, while JavaScript is maintained by the Mozilla Foundation.

  • ECMAScript is used as a basis for many other programming languages, while JavaScript is used primarily for web development.

  • ECMAScript is updated regularly, while JavaScr...read more

Add your answer

Q15. diff between arrow function and normal function

Ans.

Arrow functions are shorter syntax for writing function expressions. They have lexical 'this' binding.

  • Arrow functions do not have their own 'this', 'arguments', 'super', or 'new.target' keywords.

  • Arrow functions cannot be used as constructors and do not have a prototype property.

  • Arrow functions are anonymous and cannot be named.

  • Arrow functions have a shorter syntax compared to normal functions.

  • Arrow functions have a lexical 'this' binding, meaning they inherit the 'this' value...read more

View 1 answer

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

Q17. what is generator functions? what is symbols? write an implementation for const keyword to support in es05.

Ans.

Generator functions and symbols in JavaScript. Implementation of const keyword in ES5.

  • Generator functions are functions that can be paused and resumed, allowing for lazy evaluation of data.

  • Symbols are a new primitive type in ES6 that can be used as unique identifiers.

  • To implement const in ES5, we can use Object.defineProperty to create a read-only property on an object.

Add your answer
Frequently asked in

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

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

Q20. What is rest and spread operator?

Ans.

Rest and spread operators are used in JavaScript to manipulate arrays and objects.

  • Rest operator allows us to represent an indefinite number of arguments as an array.

  • Spread operator allows us to spread an array or object into individual elements.

  • Rest operator is denoted by three dots (...)

  • Spread operator is also denoted by three dots (...) but is used in a different context.

  • Rest operator can be used in function parameters and destructuring assignments.

  • Spread operator can be us...read more

Add your answer

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

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

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

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

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

Q26. Mention some of the JavaScript datatypes?

Ans.

JavaScript has several datatypes including string, number, boolean, object, array, null, and undefined.

  • String: represents a sequence of characters

  • Number: represents numeric values

  • Boolean: represents true or false

  • Object: represents a collection of key-value pairs

  • Array: represents an ordered list of values

  • Null: represents the intentional absence of any object value

  • Undefined: represents an uninitialized variable

View 2 more answers

Q27. What is the advantage of inner html on javascript

Ans.

Inner HTML allows dynamic manipulation of HTML content using JavaScript.

  • Inner HTML can be used to add, remove or modify HTML elements on a webpage.

  • It provides a simple and efficient way to update the content of a webpage without reloading the entire page.

  • Inner HTML can also be used to create dynamic user interfaces and interactive web applications.

  • However, it is important to sanitize user input to prevent security vulnerabilities such as cross-site scripting (XSS) attacks.

Add your answer
Q28. JavaScript Question

What are arrow functions?

Ans.

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

  • Arrow functions have a shorter syntax compared to regular functions.

  • They do not have their own 'this' value.

  • They do not have the 'arguments' object.

  • They cannot be used as constructors with the 'new' keyword.

  • They are commonly used in functional programming and with array methods like 'map' and 'filter'.

Add your answer

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

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

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

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

Q33. what is difference between normal function and arrow function?

Ans.

Normal functions are defined using the function keyword, while arrow functions are defined using the => syntax.

  • Normal functions are hoisted, while arrow functions are not hoisted.

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

  • Arrow functions do not have their own 'arguments' object.

  • Arrow functions are more concise and have implicit return.

  • Arrow functions cannot be used as constructors.

Add your answer

Q34. How to fetch all input values in javascript

Ans.

To fetch all input values in javascript, we can use the document.querySelectorAll() method.

  • Use document.querySelectorAll() method to select all input elements

  • Loop through the selected elements to get their values

  • Store the values in an array or object for further use

Add your answer
Frequently asked in

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

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

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

Q38. 5] How is Var different from Let ?

Ans.

Var is function-scoped and can be redeclared, while Let is block-scoped and cannot be redeclared.

  • Var can be hoisted to the top of its scope, while Let cannot.

  • Var can be declared without being initialized, while Let must be initialized before use.

  • Var can cause unexpected behavior in loops, while Let avoids this issue.

  • Var can be used to declare global variables, while Let cannot.

  • Var can be redeclared within its scope, while Let cannot.

Add your answer

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

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

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

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

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

Q44. What is the Dom in javascript

Ans.

The DOM (Document Object Model) in JavaScript is a programming interface for web documents. It represents the structure of a document as a tree of objects.

  • The DOM is a representation of the HTML elements on a webpage.

  • It allows JavaScript to interact with and manipulate the content and structure of a webpage.

  • DOM methods like getElementById() and querySelector() are commonly used to access and modify elements on a webpage.

Add your answer

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

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

Q47. 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
Q48. JavaScript Question

What is IIFE?

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

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

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

Q51. What is Javascript and how it is helpful in Core PHP to develop your website?

Ans.

Javascript is a scripting language used for web development. It can be used with Core PHP to add interactivity to websites.

  • Javascript is a client-side scripting language that runs in the browser

  • It can be used to add interactivity to websites, such as form validation and dynamic content

  • Core PHP is a server-side scripting language used to generate HTML pages

  • Javascript can be used with Core PHP to create dynamic web pages

  • For example, you can use Javascript to create a form that ...read more

Add your answer

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

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

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

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

Q56. Q1 difference between let and const

Ans.

let is mutable and can be reassigned, const is immutable and cannot be reassigned

  • let allows reassignment of values, const does not

  • const must be initialized with a value, let can be declared without a value

  • const is block-scoped, let is function-scoped

Add your answer

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

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

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

Q60. what is react, state , props, api....

Ans.

React is a JavaScript library for building user interfaces. State is data that can change over time within a component. Props are read-only data passed from a parent component. API stands for Application Programming Interface.

  • React is a JavaScript library for building user interfaces

  • State is data that can change over time within a component

  • Props are read-only data passed from a parent component

  • API stands for Application Programming Interface

Add your answer

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

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

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

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

Q65. How concurrency works in JS

Ans.

Concurrency in JS allows multiple tasks to run simultaneously by utilizing event loop and callback functions.

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

  • Concurrency is achieved through asynchronous operations using callbacks, promises, and async/await.

  • Event loop manages the execution of multiple tasks by queuing them in a stack and executing them one by one.

  • Web Workers allow running scripts in background threads to handle heavy computations without b...read more

Add your answer
Frequently asked in

Q66. What's the use of @track decorator. Is it mandatory to explicitly use it? If yes, for which use case?

Ans.

The @track decorator in Salesforce is used to track changes to a property in a Lightning web component.

  • Used to make a property reactive and trigger re-renders when its value changes

  • Not mandatory but recommended for properties that need to be reactive

  • Use @track when you want changes to a property to be reflected in the UI

Add your answer

Q67. Implement one function which can connect to the server socket in javascript

Ans.

Use the WebSocket API in JavaScript to connect to a server socket

  • Use the WebSocket constructor to create a new WebSocket object

  • Pass the server URL as the first argument to the WebSocket constructor

  • Handle the WebSocket events like onopen, onmessage, onerror, and onclose

Add your answer

Q68. what are the scope in javascript, describe each one.

Ans.

Scopes in JavaScript determine the accessibility of variables and functions.

  • Global scope: variables and functions declared outside any function are accessible globally

  • Local scope: variables and functions declared inside a function are only accessible within that function

  • Block scope: variables declared with let and const are only accessible within the block they are declared in

  • Function scope: variables declared with var are accessible within the function they are declared in

Add your answer
Frequently asked in

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

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

Q71. What js .net core

Ans.

ASP.NET Core is a cross-platform, high-performance framework for building modern, cloud-based, internet-connected applications.

  • Open-source framework developed by Microsoft

  • Supports multiple platforms including Windows, macOS, and Linux

  • Used for building web applications, APIs, and microservices

  • Provides high performance and scalability

  • Includes features like dependency injection, middleware, and MVC pattern

Add your answer

Q72. difference between forIn and forOf loop,

Ans.

forIn loop iterates over the enumerable properties of an object, while forOf loop iterates over the values of an iterable object.

  • forIn loop is used for iterating over object properties, while forOf loop is used for iterating over array elements.

  • forIn loop can be used with objects, while forOf loop can be used with arrays, strings, maps, sets, etc.

  • Example: forIn loop - for (let key in object) { console.log(key); }

  • Example: forOf loop - for (let value of array) { console.log(val...read more

Add your answer

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

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

Q75. How JS execution happend

Ans.

JS execution happens in two main phases: creation and execution.

  • During creation phase, variables are hoisted and memory space is allocated.

  • During execution phase, code is executed line by line.

  • JS uses a single-threaded, synchronous execution model.

  • Functions are first-class citizens in JS, allowing for higher-order functions and closures.

  • Event loop and callback queue are used for handling asynchronous operations.

Add your answer

Q76. 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, ,

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

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

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

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

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

Q82. What are higher order functions in javascript

Ans.

Higher order functions in JavaScript are functions that can take other functions as arguments or return functions as output.

  • Higher order functions can be used to create more flexible and reusable code.

  • Examples include functions like map, filter, and reduce in JavaScript.

  • They allow for functions to be passed as parameters, making code more concise and readable.

Add your answer
Q83. JavaScript Question

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

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

Q85. Difference between Async and Await in JavaScript.

Ans.

Async and Await are keywords used in JavaScript to handle asynchronous operations in a synchronous way.

  • Async is used to declare a function as asynchronous, which means it will always return a promise.

  • Await is used to pause the execution of a function until a promise is settled (resolved or rejected).

  • Async functions can contain one or more await expressions to wait for promises to be resolved.

  • Async functions always return a promise, which allows chaining multiple async functio...read more

Add your answer

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

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

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

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

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

Q91. How can we create elements dynamically in JavaScript

Ans.

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

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

  • Set attributes and content for the element using methods like setAttribute() and innerHTML

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

Add your answer

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

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

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

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

Q96. Difference between regular function and arrow function

Ans.

Regular functions are defined using the function keyword, while arrow functions use the => syntax.

  • Arrow functions have a shorter syntax than regular functions.

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

  • Arrow functions cannot be used as constructors.

  • Regular functions can be used as methods on objects, while arrow functions cannot.

  • Arrow functions are always anonymous, while regular functions can be named or anonymous.

Add your answer
Q97. JavaScript Question

What is Temporal Dead Zone?

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

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

Q99. Create form a to console.log input value

Ans.

Create a form and log input value to console

  • Create an HTML form element with input field

  • Add an event listener to the form submit event

  • Retrieve the input value using JavaScript

  • Log the input value to console

Add your answer

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

Interview experiences of popular companies

3.7
 • 10k Interviews
3.9
 • 7.7k Interviews
3.7
 • 7.3k Interviews
3.8
 • 5.4k Interviews
3.7
 • 5.1k Interviews
3.8
 • 4.6k Interviews
3.6
 • 3.6k Interviews
3.8
 • 2.7k Interviews
4.0
 • 745 Interviews
4.0
 • 244 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