0% found this document useful (0 votes)
12 views10 pages

Javascript Imp Q&A

Javascript answrs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views10 pages

Javascript Imp Q&A

Javascript answrs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Javascript Question & Answer

What is JavaScript?
JavaScript is a high-level, interpreted programming language used to create dynamic and
interactive web pages.

What are the key features of JavaScript?


Key features of JavaScript include:

Dynamic typing

Prototypal inheritance

First-class functions

Closures

Asynchronous programming with callbacks and promises

What are the different data types in JavaScript?


JavaScript has six primitive data types: string, number, boolean, null, undefined, and
symbol. It also has one complex data type: object.

Explain the difference between == and === in JavaScript?


== is the equality operator, which performs type coercion if the operands are of different
types.

=== is the strict equality operator, which does not perform type coercion and checks both
value and type.

What is hoisting in JavaScript?


Hoisting is a JavaScript mechanism where variables and function declarations are moved to
the top of their containing scope during compilation.

Explain the event bubbling and event capturing in JavaScript?


Event bubbling is the propagation of an event from the target element to its ancestors.

Event capturing is the propagation of an event from the top of the DOM tree down to the
target element.
What is closure in JavaScript?
A closure is a combination of a function and the lexical environment within which that
function was declared. It allows a function to access its outer scope even after the outer
scope has closed.

What is a callback function in JavaScript?


A callback function is a function passed as an argument to another function and is invoked
after some operation has been completed, often asynchronously.

What is the prototype chain in JavaScript?


The prototype chain is a mechanism for inheritance in JavaScript, where objects inherit
properties and methods from their prototype objects.

Explain the difference between let, const, and var in JavaScript?


var: Function-scoped, can be redeclared and reassigned.

let: Block-scoped, cannot be redeclared but can be reassigned.

const: Block-scoped, cannot be redeclared or reassigned.

JavaScript Functions:

What are arrow functions in JavaScript?


Arrow functions are a shorter syntax for writing function expressions, with implicit return
and lexical this binding.

What is the use of the bind() method in JavaScript?


The bind() method creates a new function that, when called, has its this keyword set to a
specified value.

Explain the apply() and call() methods in JavaScript?


apply(): Calls a function with a given this value and arguments provided as an array.

call(): Calls a function with a given this value and arguments provided individually.
What is a higher-order function in JavaScript?
A higher-order function is a function that takes another function as an argument or returns
a function as a result.

What is a pure function in JavaScript?


A pure function is a function that always returns the same result for the same input and
does not cause side effects

JavaScript Objects and Prototypes:

What is an object in JavaScript?


An object is a collection of key-value pairs where keys are strings (or symbols) and values
can be any data type.

How do you create an object in JavaScript?


Objects can be created using object literals, the new keyword with a constructor function,
or the Object.create() method.

Explain prototypal inheritance in JavaScript?


Prototypal inheritance is a mechanism where objects inherit properties and methods from
their prototype objects. Each object has a prototype object from which it inherits properties
and methods.

What is the prototype property in JavaScript?


The prototype property allows you to add properties and methods to all instances of a
constructor function.

What is the difference between prototype and proto in JavaScript?


prototype: A property of constructor functions that is used to add properties and methods
to all instances of the constructor.

proto: A property of objects that points to the object's prototype.


JavaScript Arrays:

How do you create an array in JavaScript?


Arrays can be created using array literals or the Array constructor.

What are array methods in JavaScript?


Array methods are built-in functions that can be called on arrays to perform operations
such as adding, removing, or modifying elements.

Explain the map(), filter(), and reduce() methods in JavaScript?


map(): Creates a new array by applying a function to each element in the original array.

filter(): Creates a new array with elements that pass a test specified by a function.

reduce(): Executes a reducer function on each element of the array, resulting in a single
output value.

What is the difference between forEach() and map() methods in JavaScript?


forEach(): Calls a function for each element in the array but does not return a new array.

map(): Calls a function for each element in the array and returns a new array with the
results.

How do you check if an object is an array in JavaScript?


You can check if an object is an array using the Array.isArray() method.

JavaScript DOM Manipulation:

What is the DOM in JavaScript?


The Document Object Model (DOM) is a programming interface for HTML and XML
documents. It represents the structure of a document as a tree of objects.

How do you access and modify elements in the DOM using JavaScript?
You can access and modify elements in the DOM using methods such as getElementById(),
getElementsByClassName(), querySelector(), and querySelectorAll(). You can then modify
element properties and attributes using JavaScript.
What is event delegation in JavaScript?
Event delegation is a technique where you attach an event listener to a parent element
rather than individual child elements. This allows you to handle events on dynamically
created or nested elements.

What are event listeners in JavaScript?


Event listeners are functions that are called when a specific event occurs, such as a click,
hover, or keypress event

Explain the difference between event bubbling and event capturing?


Event bubbling: Events are first captured at the target element and then bubble up through
its ancestors.

Event capturing: Events are first captured at the top of the DOM tree and then propagate
down to the target element.

JavaScript Promises and Asynchronous Programming:

What is asynchronous programming in JavaScript?


Asynchronous programming is a programming paradigm where operations are performed
asynchronously, allowing other operations to run in parallel without blocking the main
thread.

What is a Promise in JavaScript?


A Promise is an object that represents the eventual completion or failure of an
asynchronous operation and its resulting value.

How do you handle errors in Promises in JavaScript?


Errors in Promises can be handled using the catch() method or by chaining a second callback
function to the then() method.

Explain the difference between Promise.all() and Promise.race() methods?


Promise.all(): Returns a single Promise that resolves when all of the promises in the iterable
argument have resolved.
Promise.race(): Returns a Promise that resolves or rejects as soon as one of the promises in
the iterable resolves or rejects.

What is async/await in JavaScript?


async/await is a syntactic sugar for asynchronous programming in JavaScript. It allows you
to write asynchronous code in a synchronous style using the async and await keywords.

JavaScript ES Features:
What are template literals in JavaScript?
Template literals are string literals that allow embedded expressions and support multi-line
strings.

What are arrow functions in JavaScript?


Arrow functions are a shorter syntax for writing function expressions, with implicit return
and lexical this binding.

What is destructuring assignment in JavaScript?


Destructuring assignment is a syntax that allows you to extract values from arrays or objects
and assign them to variables.

What are default parameters in JavaScript?


Default parameters allow you to specify default values for function parameters if no value
or undefined is passed.

What are rest parameters in JavaScript?


Rest parameters allow you to represent an indefinite number of arguments as an array in a
function definition.

What are modules in JavaScript?


Modules are reusable pieces of code that encapsulate implementation details and provide
an interface for interacting with other code.

What is the export keyword in JavaScript?


The export keyword is used to export functions, objects, or primitive values from a module
to make them available for use in other modules.
What is the import keyword in JavaScript?
The import keyword is used to import functions, objects, or primitive values from another
module into the current module.

Explain the difference between named exports and default exports in


JavaScript modules?
Named exports: Allows you to export multiple values from a module using named exports.

Default exports: Allows you to export a single value from a module as the default export.

How do you create a module in JavaScript?


Modules can be created using the export keyword to export values and the import keyword
to import values from other modules.

=========================================================================

You might also like