Let's Learn Vocabularies

আপনি এখনো কোন Lesson Select করেন নি

একটি Lesson Select করুন।

এই Lesson এ এখনো কোন Vocabulary যুক্ত করা হয়নি।

নেক্সট Lesson এ যান

Frequently Asked Questions

1. the difference between var, let, and const

    In JavaScript, var, let, and const are used to declare variables, but they differ in scope and mutability: var is function-scoped and can be re-declared and updated, while let and const are block-scoped, with let allowing updates and const preventing both updates and re-declarations.

2. the difference between map(), forEach(), and filter()

forEach() will not return anything. forEach() returns undefined. filter() method will return an array of matching elements else will return an empty array if no matching happens. If you have a requirement to modify the current array and are expecting a modified one, then you should go with map() .

3. explain arrow functions and how they are different from regular functions

Arrow functions, introduced in ES6, offer a concise syntax for defining functions in JavaScript, often used for simple operations, while regular functions provide more flexibility and control, especially when needing to use this or arguments in a dynamic context.

4. how JavaScript Promises work

A Promise in JavaScript is an object that represents the eventual completion or failure of an asynchronous operation. It helps manage asynchronous code execution, avoiding "callback hell." A promise has three states: pending (initial state), fulfilled (operation succeeded), or rejected (operation failed). When a promise is fulfilled, the .then() method is executed, and if it fails, the .catch() method handles the error. Additionally, .finally() runs regardless of success or failure. Promises can be chained to handle multiple asynchronous tasks sequentially. For multiple promises, Promise.all() waits for all to resolve, while Promise.race() returns the first resolved or rejected promise. A cleaner way to work with promises is async/await, which allows writing asynchronous code in a synchronous style. Promises play a crucial role in modern JavaScript, especially in API calls, database queries, and handling real-time events efficiently.

5. how closures work in JavaScript

A closure in JavaScript is a function that retains access to variables from its outer scope even after the outer function has finished executing. This happens because JavaScript functions remember the environment in which they were created. Closures are useful for data privacy, as they allow variables to remain accessible only within a specific function, preventing external modification. They are commonly used in counters, function factories, event listeners, and callbacks, enabling functions to store and manipulate persistent data without using global variables. By leveraging closures, developers can write more efficient, modular, and secure JavaScript code.