ASSIGNMENT-07 : Submitted by

Md Nizam Uddin

Student ID: WEB7-1905

Batch 07

Question & Answer Section


Question 1 : What is the Difference between map, filter, forEach and find


Ans: Difference between map, filter, forEach and find are as follows:


map: creates a new array with the same length as the input array and applies a provided function to each element in the input array. The returned values from the function are used to populate the new array. map does not modify the original array.
filter: creates a new array containing all elements of the input array that satisfy a provided condition. The condition is specified using a callback function that returns a boolean value.
forEach: executes a provided function once for each element in the input array. It does not create a new array and does not return a value.
find: returns the first element in the input array that satisfies a provided condition. The condition is specified using a callback function that returns a boolean value. If no elements match, it returns undefined..


Question 2: What is the difference between LocalStorage, SessionStorage, and Cookies?


Ans: Difference between LocalStorage, SessionStorage, and Cookies are as follows;


LocalStorage: It stores data with no expiration date and persists even after the browser or the computer is restarted. It can only be cleared through JavaScript or clearing the browser cache. It can store larger amounts of data (typically up to 5-10 MB) than cookies, and can only be accessed by the same domain that created it.


SessionStorage: It can also store larger amounts of data than cookies (typically up to 5-10 MB) but is only available for the duration of the session. It stores data only for a single session, which ends when the browser is closed. It is useful for storing temporary data that should be cleared when the user leaves the site.


Cookies: It can have an expiration date or can persist until deleted. It can be cleared through JavaScript or by the user manually deleting them. They are limited to a maximum size of 4KB and can be accessed by any website that has access to them.


Question 3: what is even loop? How does it work?


Ans: In JavaScript, the event loop is a key mechanism for handling asynchronous operations and executing code in a non-blocking way. It is a loop that constantly checks the JavaScript runtime environment for new events, and executes the appropriate code for each event as it is encountered.
When an event is triggered, such as a user clicking a button on a web page or an asynchronous operation completing, it is added to a queue called the event queue. The event loop constantly checks this queue for new events, and when it encounters an event, it executes the appropriate code that is associated with that event.


Question 4: Write about quizTimer and chooseQuiz function work?

quizTimer: The function starts by checking if the dismiss parameter is true, and if so, it clears an interval timer that was previously set by this function (stored in the timer variable) and returns from the function. If dismiss is not true, the function sets an interval timer that runs every second (1000 milliseconds).


chooseQuiz: The function starts by searching for an object with an id property that matches the id property of the quiz data located at the specified index. This is done using the find method on an array called answers, which is assumed to already exist in the code. Finally, the function calls a displayAnswers function with the answers array as its argument.


Copyright ©2023 Allright Reserved