Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 9

Fresher Level

What is a JavaScript function?

Answer:
A JavaScript function is a block of code designed to perform a particular task. It
is executed when "something" invokes it (calls it).

JavaScript function क्या है?

उत्तर:
एक JavaScript function कोड का एक ब्लॉक होता है जिसे किसी विशेष कार्य को पूरा करने के लिए डिज़ाइन किया गया है। इसे तब
निष्पादित किया जाता है जब "कु छ" इसे कॉल करता है।
How do you define a function in JavaScript?

Answer:

javascript
Copy code
function functionName(parameters) {
// code to be executed
}
JavaScript में function को कै से परिभाषित करते हैं?

उत्तर:
javascript
Copy code
function functionName(parameters) {
// निष्पादित होने वाला कोड
}
What is the purpose of the return statement in a function?

Answer:
The return statement stops the execution of a function and returns a value to the
caller.

Function में return कथन का क्या उद्देश्य होता है?

उत्तर:
return कथन एक function के निष्पादन को रोकता है और कॉल करने वाले को एक मान लौटाता है।
Intermediate Level
What are function expressions in JavaScript?

Answer:
A function expression is created when a function is assigned to a variable. The
function can be named or anonymous.

javascript
Copy code
const myFunction = function() {
// code
};
JavaScript में function expressions क्या होते हैं?

उत्तर:
एक function expression तब बनता है जब एक function को एक variable को सौंपा जाता है। function नामित या
गुमनाम हो सकता है।
javascript
Copy code
const myFunction = function() {
// कोड
};
What are arrow functions and how are they different from regular functions?

Answer:
Arrow functions are a shorter syntax for writing functions in JavaScript. They do
not have their own this context, making them useful for non-method functions.

javascript
Copy code
const add = (a, b) => a + b;
Arrow functions क्या होते हैं और ये साधारण functions से कै से भिन्न होते हैं?

उत्तर:
Arrow functions JavaScript में functions लिखने के लिए एक छोटा syntax है। इनके पास अपना this
context नहीं होता, जो इन्हें non-method functions के लिए उपयोगी बनाता है।
javascript
Copy code
const add = (a, b) => a + b;
Explain higher-order functions in JavaScript.

Answer:
Higher-order functions are functions that can take other functions as arguments or
return them as output.

javascript
Copy code
function higherOrder(fn) {
return function() {
fn();
};
}
JavaScript में higher-order functions समझाइए।

उत्तर:
Higher-order functions वे functions होते हैं जो अन्य functions को arguments के रूप में ले सकते हैं या
उन्हें output के रूप में लौटा सकते हैं।
javascript
Copy code
function higherOrder(fn) {
return function() {
fn();
};
}
Advanced Level
What is function currying? Provide an example.

Answer:
Function currying is a technique of transforming a function that takes multiple
arguments into a sequence of functions that each take a single argument.

javascript
Copy code
function curry(fn) {
return function(a) {
return function(b) {
return fn(a, b);
};
};
}
const add = (a, b) => a + b;
const curriedAdd = curry(add);
console.log(curriedAdd(1)(2)); // 3
Function currying क्या है? एक उदाहरण दें।

उत्तर:
Function currying एक तकनीक है जो एक function को जो कई arguments लेता है, उसे functions के अनुक्रम में
बदल देता है जो प्रत्येक एकल argument लेता है।
javascript
Copy code
function curry(fn) {
return function(a) {
return function(b) {
return fn(a, b);
};
};
}
const add = (a, b) => a + b;
const curriedAdd = curry(add);
console.log(curriedAdd(1)(2)); // 3
What is a closure in JavaScript?

Answer:
A closure is a function that has access to its own scope, the scope of the outer
function, and the global scope.

javascript
Copy code
function outerFunction() {
let outerVariable = 'I am from outer function';
return function innerFunction() {
console.log(outerVariable);
};
}
const closureFunction = outerFunction();
closureFunction(); // I am from outer function
JavaScript में closure क्या है?

उत्तर:
Closure एक function होता है जिसे अपना scope, बाहरी function का scope, और global scope तक पहुंच
होती है।
javascript
Copy code
function outerFunction() {
let outerVariable = 'I am from outer function';
return function innerFunction() {
console.log(outerVariable);
};
}
const closureFunction = outerFunction();
closureFunction(); // I am from outer function
What are IIFEs (Immediately Invoked Function Expressions)?

Answer:
An IIFE is a function that runs as soon as it is defined.

javascript
Copy code
(function() {
console.log('IIFE executed');
})();
IIFEs (Immediately Invoked Function Expressions) क्या हैं?

उत्तर:
एक IIFE एक function होता है जो जैसे ही परिभाषित किया जाता है, चल जाता है।
javascript
Copy code
(function() {
console.log('IIFE executed');
})();
Explain the concept of memoization in functions.

Answer:
Memoization is an optimization technique where a function stores the results of
expensive function calls and returns the cached result when the same inputs occur
again.

javascript
Copy code
function memoize(fn) {
const cache = {};
return function(...args) {
const key = JSON.stringify(args);
if (cache[key]) {
return cache[key];
} else {
const result = fn(...args);
cache[key] = result;
return result;
}
};
}
const add = (a, b) => a + b;
const memoizedAdd = memoize(add);
console.log(memoizedAdd(1, 2)); // 3 (calculated)
console.log(memoizedAdd(1, 2)); // 3 (cached)
Functions में memoization की अवधारणा समझाइए।

उत्तर:
Memoization एक optimization तकनीक है जहाँ एक function महंगे function कॉल के परिणामों को संग्रहीत करता है
और जब वही inputs फिर से होते हैं तो cached परिणाम लौटाता है।
javascript
Copy code
function memoize(fn) {
const cache = {};
return function(...args) {
const key = JSON.stringify(args);
if (cache[key]) {
return cache[key];
} else {
const result = fn(...args);
cache[key] = result;
return result;
}
};
}
const add = (a, b) => a + b;
const memoizedAdd = memoize(add);
console.log(memoizedAdd(1, 2)); // 3 (calculated)
console.log(memoizedAdd(1, 2)); // 3 (cached)
These questions cover a range of topics within JavaScript functions, from basic
definitions and syntax to more advanced concepts like closures, currying, and
memoization.

or do 50 questions do basics se advanced level ke ekdmm or thore technical ho


ghumane vale b ho kch
ChatGPT
Memory updated
Here's a comprehensive list of 50 JavaScript interview questions covering basics to
advanced levels, including technical and engaging questions:

Basics
What is JavaScript?

Answer: JavaScript is a high-level, interpreted programming language used to create


dynamic and interactive websites.
What are the different data types in JavaScript?

Answer: Primitive data types include string, number, boolean, null, undefined, and
symbol. Objects are also a data type.
Explain the difference between null and undefined.

Answer: null is an assignment value representing no value, while undefined means a


variable has been declared but not assigned a value.
How do you declare a variable in JavaScript?

Answer: Variables are declared using var, let, or const followed by the variable
name.
What is the difference between var, let, and const?

Answer: var has function scope, let has block scope, and const is used for
constants whose values cannot be changed once defined.
What are JavaScript functions?

Answer: Functions are blocks of code designed to perform a particular task and are
executed when called.
How do you define a function in JavaScript?

Answer: Functions can be defined using the function keyword or as arrow functions
(=> syntax).
What is a callback function?

Answer: A callback function is a function passed as an argument to another function


to be executed later.
What are anonymous functions?

Answer: Anonymous functions are functions without a name and are typically defined
inline.
Explain hoisting in JavaScript.

Answer: Hoisting is JavaScript's default behavior of moving declarations to the top


of the current scope during compilation.
Intermediate
What are closures in JavaScript?
Answer: Closures are functions that retain access to the variables in their lexical
scope, even when the function is executed outside that scope.
Explain the concept of this keyword in JavaScript.

Answer: this refers to the object that owns the currently executing code.
What are Immediately Invoked Function Expressions (IIFE)?

Answer: IIFE are functions that are executed immediately after they are created.
How do you handle errors in JavaScript?

Answer: Errors are handled using try, catch, and finally blocks.
What is event delegation in JavaScript?

Answer: Event delegation refers to the technique of using a single event listener
to manage events for multiple elements.
What is the difference between == and === operators?

Answer: == checks for equality after type coercion, while === checks for equality
without type coercion.
What are JavaScript promises?

Answer: Promises represent the eventual completion or failure of an asynchronous


operation and allow chaining of asynchronous operations.
What are ES6 arrow functions? How are they different from regular functions?

Answer: Arrow functions are a concise syntax for writing functions in JavaScript,
and they do not have their own this context.
Explain the concept of let and const in block-scoped variables.

Answer: let and const are block-scoped variables introduced in ES6. let allows
reassignment, while const is for constants.
What is destructuring assignment in JavaScript?

Answer: Destructuring assignment allows you to unpack values from arrays or


properties from objects into distinct variables.
Advanced
What is the prototype chain in JavaScript?

Answer: The prototype chain is used to implement inheritance in JavaScript by


linking objects to other objects.
Explain async/await in JavaScript.

Answer: Async/await is a syntactic sugar for writing asynchronous code in a


synchronous-like manner, introduced in ES8.
What are generator functions in JavaScript?

Answer: Generator functions allow you to pause and resume function execution,
yielding multiple values over time.
Explain the concept of currying in JavaScript functions.

Answer: Currying is the process of converting a function that takes multiple


arguments into a sequence of functions that each take a single argument.
What are the differences between Object.freeze(), Object.seal(), and
Object.preventExtensions()?

Answer: Object.freeze() prevents modifications to existing properties,


Object.seal() seals an object, preventing new properties, and
Object.preventExtensions() prevents new properties from being added.
What are modules in JavaScript?
Answer: Modules are reusable pieces of code that can be exported from one program
and imported into another.
How do you handle asynchronous code in JavaScript?

Answer: Asynchronous code is handled using callbacks, promises, async/await, and


event listeners.
What are the different ways to create objects in JavaScript?

Answer: Objects can be created using object literals, constructors, factory


functions, and Object.create() method.
Explain the use of bind(), call(), and apply() in JavaScript.

Answer: These methods are used to manipulate the this context of functions. bind()
creates a new function with a specified this value, while call() and apply() invoke
the function immediately.
What is memoization? How is it implemented in JavaScript?

Answer: Memoization is an optimization technique where the results of expensive


function calls are cached and reused when the same inputs occur again.
Engaging and Technical
What is the event loop in JavaScript?

Answer: The event loop is responsible for executing the code, collecting and
processing events, and executing queued sub-tasks.
How does JavaScript handle hoisting of variables and functions?

Answer: Variable declarations are hoisted to the top of their scope, while function
declarations are fully hoisted.
Explain the concept of prototypal inheritance in JavaScript.

Answer: Prototypal inheritance allows objects to inherit properties and methods


from other objects by linking prototypes.
What are some common design patterns used in JavaScript?

Answer: Examples include Singleton, Factory, Observer, and Module patterns, used to
solve recurring problems in software design.
How does JavaScript handle memory management?

Answer: JavaScript uses automatic garbage collection to manage memory allocation


and deallocation for objects.
What are the differences between synchronous and asynchronous code execution in
JavaScript?

Answer: Synchronous code executes line by line, blocking further execution until it
completes. Asynchronous code allows multiple operations to be performed
concurrently, using callbacks or promises for handling results.
Explain the concept of lexical scoping in JavaScript.

Answer: Lexical scoping determines the accessibility of variables within nested


functions based on where the variables are defined statically in the code.
How can you achieve immutability in JavaScript?

Answer: Immutability can be achieved using Object.freeze() for objects and const
for variables to prevent changes after creation.
What are some performance considerations when writing JavaScript code?

Answer: Minimizing DOM manipulation, optimizing loops and algorithms, using event
delegation, and reducing network requests are key considerations.
40

hindi or english dono mai explain kro bss function topics ke hi


ChatGPT
Certainly! Here are JavaScript interview questions focusing on function topics,
explained in both Hindi and English:

Basics
JavaScript kya hai?

Answer (English): JavaScript is a high-level, interpreted programming language used


to create dynamic and interactive websites.
उत्तर (Hindi): JavaScript ek high-level, interpreted programming language hai jo
dynamic aur interactive websites banane ke liye istemal hota hai.
JavaScript mein data types kya hote hain?

Answer (English): Primitive data types include string, number, boolean, null,
undefined, and symbol. Objects are also a data type.
उत्तर (Hindi): Primitive data types mein string, number, boolean, null, undefined,
aur symbol shamil hote hain. Objects bhi ek data type hain.
null aur undefined mein antar kya hai?

Answer (English): null represents no value, while undefined means a variable has
been declared but not assigned a value.
उत्तर (Hindi): null kisi value ko darshata hai nahi, jabki undefined ka matlab hota
hai ki variable declare kiya gaya hai par usme koi value assign nahi ki gayi hai.
JavaScript mein variable kaise declare karte hain?

Answer (English): Variables are declared using var, let, or const followed by the
variable name.
उत्तर (Hindi): Variables var, let, ya const ka istemal karke declare kiye jate hain,
jisme variable name ke baad use hota hai.
var, let, aur const mein kya antar hai?

Answer (English): var has function scope, let has block scope, and const is used
for constants whose values cannot be changed once defined.
उत्तर (Hindi): var function scope rakhta hai, let block scope rakhta hai, aur const
un constants ke liye istemal hota hai jinke values ek baar define hone ke baad
badal nahi sakti.
Intermediate
JavaScript mein functions kya hote hain?

Answer (English): Functions are blocks of code designed to perform a particular


task and are executed when called.
उत्तर (Hindi): Functions code ke blocks hote hain jo ek vishesh task ko perform karne
ke liye design kiye gaye hote hain aur unhe call hone par execute kiya jata hai.
JavaScript mein function kaise define karte hain?

Answer (English): Functions can be defined using the function keyword or as arrow
functions (=> syntax).
उत्तर (Hindi): Functions function keyword ka istemal karke ya arrow functions (=>
syntax) se define kiye ja sakte hain.
Callback function kya hoti hai?

Answer (English): A callback function is a function passed as an argument to


another function to be executed later.
उत्तर (Hindi): Callback function ek aisi function hoti hai jo dusre function ko
argument ke roop mein pass ki jati hai aur baad mein execute hone ke liye rakhi
jati hai.
Anonymous functions kya hoti hain?

Answer (English): Anonymous functions are functions without a name and are
typically defined inline.
उत्तर (Hindi): Anonymous functions naam ke bina functions hote hain jo aam taur par
inline define kiye jate hain.
Advanced
JavaScript mein closures kya hote hain?

Answer (English): Closures are functions that retain access to the variables in
their lexical scope, even when the function is executed outside that scope.
उत्तर (Hindi): Closures functions hote hain jo apne lexical scope mein rahne wale
variables ka access retain karte hain, chahe function us scope ke bahar bhi execute
ho.
this keyword JavaScript mein kya hota hai?

Answer (English): this refers to the object that owns the currently executing code.
उत्तर (Hindi): this us object ko refer karta hai jo abhi execute hone wale code ka
owner hai.
Function currying ka concept samjhaaye.

Answer (English): Function currying is a technique of transforming a function that


takes multiple arguments into a sequence of functions that each take a single
argument.
उत्तर (Hindi): Function currying ek technique hai jisme ek function ko transform kiya
jata hai jo kai arguments leta hai, un functions ke sequence mein jo har ek single
argument leta hai.
These questions provide a thorough exploration of JavaScript functions, catering to
both basic understanding and advanced concepts, presented in both Hindi and
English.

You might also like