✅ Debouncing function in Javascript.
Debouncing makes sure that a function doesn't run too often in a short period of time.
Debouncing makes sure that a function doesn't run too often in a short period of time.
// Debouncing util
function debounce(func, wait) {
let timeout;
return function(...args) {
clearTimeout(timeout);
timeout = setTimeout(() => func.apply(this, args), wait);
};
}
// Usage
const handleResize = debounce(() => {
console.log('Resize event');
}, 300);
window.addEventListener('resize', handleResize);
✅ Challenge.(Promise)
const promise = new Promise((resolve, reject) => {
resolve('Success');
});
promise.then(result => {
console.log(result) // ?
});
console.log('End'); // ?
📌Question: what will be the output of the code snippet above?
Anonymous Quiz
38%
A) "Success", "End"
37%
B) "End", "Success"
14%
C) "Success"
11%
D) "End"
✅ Challenge. (Map)
// Create new Map
const map = new Map();
map.set('a', 1);
map.set('b', 2);
map.set('a', 3);
const keys = [];
for (const key of map.keys()) {
keys.push(key);
}
// Output
console.log(keys);
📌 Question: what will be the output of the code snippet above?
Anonymous Quiz
51%
A). ['a', 'b', 'a']
38%
B). ['a', 'b']
7%
C). ['a']
3%
D). ['b']
✅ Challenge. (Object)
const obj = {
a: 1,
b: {
c: 2
}
};
const newObj = Object.assign({}, obj);
newObj.b.c = 3;
console.log(obj.b.c);
📌 Question: what will be the output of the code snippet above?
Anonymous Quiz
8%
A). 1
34%
B). 2
43%
C). 3
16%
D). undefined
✅ Challenge. (Map)
const map1 = new Map();
const objKey = {};
const arrKey = [];
map1.set(objKey, 'object');
map1.set(arrKey, 'array');
console.log(map1.get(objKey));
console.log(map1.get(arrKey));
📌 Question: what will be the output of the code snippet above?
Anonymous Quiz
24%
A). object, undefined
48%
B). object, array
14%
C). undefined, array
14%
D). undefined, undefined
✅ Challenge. (Symbol)
const sym1 = Symbol('foo');
const sym2 = Symbol('foo');
console.log(sym1 === sym2);
📌 Question: what will be the output of code snippet above?
Anonymous Quiz
55%
A). true
29%
B). false
13%
C). undefined
4%
D). null
✅ Challenge. (Object)
const employee = {
name: 'Bob',
position: 'Developer',
details: {
skills: ['JavaScript', 'Node.js'],
experience: 5
}
};
const cloneEmployee = JSON.parse(JSON.stringify(employee));
cloneEmployee.details.skills.push('React');
console.log(employee.details.skills);
📌 Question: what will be the output of the code snippet above?
Anonymous Quiz
34%
A) ['JavaScript', 'Node.js']
49%
B) ['JavaScript', 'Node.js', 'React']
10%
C) ['React']
8%
D) Error
✅ Challenge. (Map)
// Create new Map
const map = new Map();
map.set('a', 1);
map.set('b', 2);
map.set('a', 3);
const keys = [];
for (const key of map.keys()) {
keys.push(key);
}
// Output
console.log(keys);
📌 Question: what will be the output of the code snippet above?
Anonymous Quiz
61%
A). ['a', 'b', 'a']
29%
B). ['a', 'b']
6%
C). ['a']
3%
D). ['b']