Interview related question collection for webdevs
যে জিনিসগুলো এখন জাস্ট ধারণা রেখে দাও। বুঝতে পারলে ভালো। না বুঝতে পারলেও কোন সমস্যা নাই। আমাদের এই কোর্স এ তেমন লাগবে না। তবে মাঝে মধ্যে ইন্টারভিউতে লেগে যেতে পারে। বা কিছুদিন পরে লেগে যেতেও পারে।
৯. class কিভাবে ডিক্লেয়ার করে
১০. inheritance কি জিনিস
১১. prototypical inheritance এর কনসেপ্টটা কি (এইটা মাঝে মধ্যে ইন্টারভিউতে জিজ্ঞেস করে বসে)
COMMON INTERVIEW QUESTIONS ON THE INTERVIEW
What's the difference between filter and find?
What is the difference between for..of and for..in?
How do you empty an array?
Difference between class and object.
What is a Prototype chain? Or how does inheritance work in JavaScript?
What does d
estructuring do in es6? Is optional chaining is same as ternary operator?
What do you mean by dot notation and bracket notation? When should you use dot notation or bracket notation?
Interview questions
Tell me something about JS engine v8 internal mechanism.
What is event loop in JavaScript?
If javascript is single threaded, how does it handle asynchronous call?
Can you explain the difference between an async function and a regular function in JavaScript?
What's the error handling strategy for promises that were rejected while awaiting?
What are the states of a promise?
Can you explain what the
.then()method does?
| Method | Purpose | Returns | Mutates Original Array |
.map() | Transforms each element into a new value. | A new array containing the results of the callback function. | No |
.filter() | Selects elements that meet a specified condition. | A new array containing only the elements for which the callback returns true. | No |
.forEach() | Executes a function once for each array element. | undefined (used for side effects, like printing to the console). | No (but the callback can mutate the elements themselves). |
That's a great list of foundational and advanced JavaScript concepts! I'll provide concise, high-value answers for the first set of questions.
1. Array Iteration Methods
1. What's the difference between map, forEach, filter?
| Method | Purpose | Returns | Mutates Original Array |
| .map() | Transforms each element into a new value. | A new array containing the results of the callback function. | No |
| .filter() | Selects elements that meet a specified condition. | A new array containing only the elements for which the callback returns true. | No |
| .forEach() | Executes a function once for each array element. | undefined (used for side effects, like printing to the console). | No (but the callback can mutate the elements themselves). |
2. What's the difference between filter and find?
.filter(): Returns an array containing all elements that satisfy the test.
.find(): Returns the first element that satisfies the test. If no element satisfies the test, it returns
undefined.
3. What is the difference between for..of and for..in?
| Loop | Purpose | Iterates Over | Yields | Best Used For |
for...in | Iterates over the properties of an object (including inherited, though usually only own properties are desired). | Object Properties (keys) | Strings (property names) | Objects, debugging, or when you need the property name. |
for...of | Iterates over the values of an iterable collection (like Arrays, Strings, Maps, Sets). | Iterable Data (values) | Values (data contained in the iterable) | Arrays, Strings, and other iterable data structures. |
4. How do you empty an array?
There are a few ways, but the most common and clear methods are:
Setting
lengthto 0 (Preferred for re-use):myArray.length = 0;This is the fastest method and preserves the original array reference, which is useful if the array is referenced by other variables.
Re-assigning to a new array:
myArray = [];This is simple and idiomatic, but it creates a new array. Any other variables that hold a reference to the original array will still point to the old data.
2. Object-Oriented & Modern JS
5. Difference between class and object.
Class (the blueprint 🏗️): A template or blueprint for creating objects. It defines properties (data) and methods (functions) that the created objects will have. In JavaScript, classes are syntactic sugar over the existing prototype-based inheritance model.
Object (the house 🏠): An instance of a class. It is a concrete entity that has specific data values defined by the class's properties.
6. What is a Prototype chain? Or how does inheritance work in JavaScript?
The Prototype Chain is the mechanism through which JavaScript objects inherit features from one another.
Every object has an internal property,
[[Prototype]](exposed viaobject.__proto__), which points to another object, its prototype.When you try to access a property or method on an object, and that property isn't found directly on the object, JavaScript looks at the object's prototype. If it's still not found, it looks at that prototype's prototype, and so on.
This creates a "chain" of objects. The search continues up the chain until the property is found, or until the end of the chain is reached (which is
null).
7. What does destructuring do in ES6?
Destructuring is a convenient syntax that allows you to extract values from arrays or properties from objects into distinct, local variables.
Array Destructuring: Extracts elements by position.
const [first, second] = [1, 2];
Object Destructuring: Extracts properties by name.
const { name, age } = person;
8. Is optional chaining the same as the ternary operator?
No, they are different.
| Feature | Optional Chaining (?.) | Ternary Operator (? :) |
| Purpose | Prevents errors when accessing properties of a null or undefined object. | Used for a simple conditional expression (if/else). |
| Return | Returns undefined if the reference before ?. is null or undefined. | Returns one of two defined values based on a boolean condition. |
Example:
Optional Chaining:
user?.address?.city$\rightarrow$ Accessescityonly ifuseranduser.addressexist.Ternary Operator:
const status = isLoggedIn ? 'Online' : 'Offline';
9. When should you use dot notation or bracket notation?
Both are used to access properties of an object, but they serve different purposes:
Dot Notation (
object.property)Use when you know the property name statically (before runtime).
Property names cannot contain spaces or special characters.
Cleaner and preferred for standard property access.
Bracket Notation (
object['property'])Use when the property name is dynamic (e.g., stored in a variable).
Use when the property name contains spaces or special characters.
Use for array-like access (e.g., looping through properties).
Example:
const propName = 'age';
const user = { name: 'Alice', 'user-id': 123 };
// Dynamic access
console.log(user[propName]); // 'age' is a variable
// Static access
console.log(user.name);
// Accessing property with a hyphen
console.log(user['user-id']);

Comments
Post a Comment