Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 30e6886

Browse files
authored
Update Interview Questions.md
1 parent 6d517f5 commit 30e6886

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

‎Coding Interview Prep/Interview Questions.md‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,43 @@
4747
* What about getDerivedStateFromProps and getSnapshotBeforeUpdate methods?
4848
* How to achieve exact behavior like componentDidUpdate in functional components?
4949
* What is debouncing and throttling? Differences between them.
50+
51+
## What is a debounce function?
52+
53+
Debounce function limits the execution of a function call and waits for a certain amount of time before running it again.
54+
55+
```js
56+
const debounceFunc = (func, delay) => {
57+
let timer;
58+
return function(...args) {
59+
const context = this;
60+
clearTimeOut(timer);
61+
timer = setTimeOut(() => {
62+
func.apply(context, args);
63+
}, delay)
64+
}}
65+
```
66+
![image](https://user-images.githubusercontent.com/34129569/174491820-d030e948-5f18-4b34-b542-29ac59394d9e.png)
67+
68+
## What is throttle function?
69+
70+
Throttling is a technique, to limit the execution of an event handler function, even when this event triggers continuously due to user actions. (ex: browser resizing)
71+
72+
```js
73+
const throttleFunc = (func, interval) => {
74+
let shouldFire = true;
75+
return function() {
76+
if (shouldFire) {
77+
func();
78+
shouldFire = false;
79+
setTimeOut(() => {
80+
shouldFire = true;
81+
}, interval)
82+
}
83+
}
84+
}
85+
```
86+
87+
![image](https://user-images.githubusercontent.com/34129569/174491911-a739956b-d882-486c-95fe-51066bad4a0c.png)
88+
5089
* Code debouncing.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /