Essential Front-End Interview Topics Explained #day 10

ยท

1 min read

Essential Front-End Interview Topics Explained  #day 10
  1. Question: ๐ˆ๐ฆ๐ฉ๐ฅ๐ž๐ฆ๐ž๐ง๐ญ ๐š ๐ƒ๐ž๐›๐จ๐ฎ๐ง๐œ๐ž ๐…๐ฎ๐ง๐œ๐ญ๐ข๐จ๐ง ๐จ๐ซ ๐–๐ซ๐ข๐ญ๐ž ๐š ๐๐ž๐›๐จ๐ฎ๐ง๐œ๐ž ๐Ÿ๐ฎ๐ง๐œ๐ญ๐ข๐จ๐ง ๐ญ๐ก๐š๐ญ ๐๐ž๐ฅ๐š๐ฒ๐ฌ ๐ข๐ง๐ฏ๐จ๐ค๐ข๐ง๐  ๐š ๐Ÿ๐ฎ๐ง๐œ๐ญ๐ข๐จ๐ง ๐ฎ๐ง๐ญ๐ข๐ฅ ๐š๐Ÿ๐ญ๐ž๐ซ ๐ง ๐ฆ๐ข๐ฅ๐ฅ๐ข๐ฌ๐ž๐œ๐จ๐ง๐๐ฌ ๐ก๐š๐ฏ๐ž ๐ž๐ฅ๐š๐ฉ๐ฌ๐ž๐ ๐ฌ๐ข๐ง๐œ๐ž ๐ญ๐ก๐ž ๐ฅ๐š๐ฌ๐ญ ๐ญ๐ข๐ฆ๐ž ๐ญ๐ก๐ž ๐Ÿ๐ฎ๐ง๐œ๐ญ๐ข๐จ๐ง ๐ฐ๐š๐ฌ ๐ข๐ง๐ฏ๐จ๐ค๐ž๐.

    Answer: function debounce(func, delay) { let timeoutId; return function (...args) { clearTimeout(timeoutId); timeoutId = setTimeout(() => { func.apply(this, args); }, delay); }; }

    const debouncedFunction = debounce(() => { console.log('Debounced function invoked'); }, 300);

    debouncedFunction(); // This call will be delayed by 300ms

  2. Question: ๐ˆ๐ฆ๐ฉ๐ฅ๐ž๐ฆ๐ž๐ง๐ญ ๐“๐ก๐ซ๐จ๐ญ๐ญ๐ฅ๐ž ๐…๐ฎ๐ง๐œ๐ญ๐ข๐จ๐ง ๐จ๐ซ ๐–๐ซ๐ข๐ญ๐ž ๐š ๐ญ๐ก๐ซ๐จ๐ญ๐ญ๐ฅ๐ž ๐Ÿ๐ฎ๐ง๐œ๐ญ๐ข๐จ๐ง ๐ญ๐ก๐š๐ญ ๐ฅ๐ข๐ฆ๐ข๐ญ๐ฌ ๐ญ๐ก๐ž ๐ข๐ง๐ฏ๐จ๐œ๐š๐ญ๐ข๐จ๐ง ๐จ๐Ÿ ๐š ๐Ÿ๐ฎ๐ง๐œ๐ญ๐ข๐จ๐ง ๐ญ๐จ ๐จ๐ง๐œ๐ž ๐ž๐ฏ๐ž๐ซ๐ฒ ๐ง ๐ฆ๐ข๐ฅ๐ฅ๐ข๐ฌ๐ž๐œ๐จ๐ง๐๐ฌ.

    Answer: function throttle(func, limit) { let inThrottle; return function (...args) { if (!inThrottle) { func.apply(this, args); inThrottle = true; setTimeout(() => { inThrottle = false; }, limit); } }; }

    const throttledFunction = throttle(() => { console.log('Throttled function invoked'); }, 300);

    throttledFunction(); // This call will be limited to once every 300ms

ย