Question 01 : What is the difference between map, filter, forEach and
find?
Ans:
map, filter, forEach and find are all higher level functions which is
used to maipulate arrays in JavaScript. There are many difference
between them but the main difference always how they mainpulate array.
For example,
map function creates a new array by applying a function to each
element in the original array.
filter function creates a new array with all the elements that pass
the test implemented by the provided function.
forEach function executes a provided function once for each element in
an array.
find function returns the first element in an array that satisfies a
provided testing function.
So, this is the main dfference between these four functions.
Question 02 : What is the difference between local storage, session
storage and cookies?
Ans:
We know that, sometimes we need to store data on the user's device and
retrieve it later. Local storage, session storage, and cookies are all
this mechanisms that web developers use to store data on the user's
device and retrieve it later. There is a difference between them.
Local storage is a type of client-side storage that allows web
applications to store data without an expiration date. On the other
hand, session storage is another type of client-side storage that
allows web applications to store data for a single browser session
only. Though cookies are small text files that web servers can send to
a user's device and retrieve later. This is the main difference that
we can see between local storage, session storage and cookies.
Question 03 : What is event loop and how does it work?
Ans:
An event loop is a programming construct that allows programs to
handle multiple events or requests simultaneously in a single thread
of execution. The basic idea of an event loop is to have a program
that listens for events or requests and responds to them as they come
in.
The event loop typically runs in a continuous loop, constantly
checking for new events or requests. When an event or request is
detected, the event loop calls the appropriate function or handler to
process the event. This can be a callback function, a coroutine, or
some other type of function that is designed to handle the specific
type of event or request. Once the event has been processed, the event
loop returns to its loop and continues checking for new events. That's
how the event loop works.
About quizTimer() function in noChange js file.
Over here, first the quizTimer() function takes a boolean parameter
known as dismiss. If the dismiss parameter is true then the function
clears the interval using clearInterval method. This is used to stop
the countdown time once the quiz is submitted or canceled.
If dismiss is false then the function sets an interval using
setInterval method. Over here, first we select the innerHTML of an
HTMl element with id count. Then we convert the count value to minute
and seconds. Then show it to the innerHTML.
There is also another conditions. If the count increase more than 60.
Then checking it's even and odd value the color will be changed.
Mainly this function is used to update the countdown on the HTML page.
About chooseQuiz() function in noChange js file.
Fist of all, the function chooseQuiz() takes two parameter known as
index and givenAns. Then The function checks if an object with an id
property equal to the id property of quizData[index].id using find()
method in an array called answers.
If it's exist then using for..of loop and then using splice() method
to replace that object with a new object that has the same properties
if it's find the object with the same id as the current quiz.
And if it's doesn't exist then this is the first attempt for this
quiz. So, the function adds a new object to the array.
Then the functions called displayAnswers() function to passing the
answers array as an argument.
Mainly this functions is used for to know the attempted quiz and pass
the array to displayAnswers() function.