Advertisement
harryyyy

Interview

Feb 12th, 2025
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 6.82 KB | Source Code | 0 0
  1. Here’s a detailed breakdown of the interview questions you provided, organized by topic:
  2.  
  3. ---
  4.  
  5. ### **HTML**
  6.  
  7. 1. **How does the `defer` attribute in a script tag work?**
  8.    - The `defer` attribute in a `<script>` tag tells the browser to download the script file in the background while parsing the HTML. The script is executed only after the HTML document has been fully parsed. This ensures that the script does not block the rendering of the page.
  9.    - Example: `<script src="script.js" defer></script>`
  10.  
  11. 2. **How would you create an accessible custom tooltip using only HTML?**
  12.    - Use the `title` attribute for simple tooltips, but for custom tooltips, use ARIA attributes for accessibility:
  13.      ```html
  14.      <div role="tooltip" aria-describedby="tooltip1">Hover me
  15.        <span id="tooltip1" role="tooltip">This is a tooltip</span>
  16.      </div>
  17.      ```
  18.    - Style the tooltip with CSS and ensure it is keyboard-accessible.
  19.  
  20. 3. **What are custom data attributes, and how are they used?**
  21.    - Custom data attributes (`data-*`) allow you to store extra information in HTML elements without affecting the rendering or behavior of the page.
  22.    - Example: `<div data-user-id="123" data-role="admin"></div>`
  23.    - Accessed in JavaScript using `element.dataset.userId`.
  24.  
  25. ---
  26.  
  27. ### **JavaScript**
  28.  
  29. 1. **How does prototypal inheritance work?**
  30.    - In JavaScript, objects inherit properties and methods from their prototype. Every object has a hidden `[[Prototype]]` property that points to another object. If a property or method is not found on the object, JavaScript looks up the prototype chain.
  31.  
  32. 2. **What is debouncing and throttling in JavaScript?**
  33.    - **Debouncing**: Delays the execution of a function until a certain amount of time has passed since the last time it was called (e.g., for search input).
  34.    - **Throttling**: Limits the execution of a function to once every specified time interval (e.g., for scroll events).
  35.  
  36. 3. **How would you implement a deep clone of an object without using libraries?**
  37.    - Use recursion and handle edge cases like circular references:
  38.      ```javascript
  39.      function deepClone(obj) {
  40.        if (obj === null || typeof obj !== 'object') return obj;
  41.        let clone = Array.isArray(obj) ? [] : {};
  42.        for (let key in obj) {
  43.          if (obj.hasOwnProperty(key)) {
  44.            clone[key] = deepClone(obj[key]);
  45.          }
  46.        }
  47.        return clone;
  48.      }
  49.      ```
  50.  
  51. 4. **How do you test a webpage for accessibility?**
  52.    - Use tools like Lighthouse, Axe, or WAVE to audit accessibility.
  53.    - Test keyboard navigation, screen reader compatibility, and ARIA roles.
  54.  
  55. 5. **How do you make images accessible?**
  56.    - Use the `alt` attribute to describe the image: `<img src="image.jpg" alt="Description of image">`.
  57.    - For decorative images, use an empty `alt` attribute: `alt=""`.
  58.  
  59. 6. **How do service workers improve web performance?**
  60.    - Service workers act as a proxy between the browser and the network, enabling features like offline caching, background sync, and push notifications.
  61.  
  62. 7. **What are the possible reasons for memory leaks?**
  63.    - Unintended global variables.
  64.    - Forgotten timers or callbacks.
  65.    - Closures retaining references.
  66.    - Detached DOM elements.
  67.  
  68. 8. **What are JavaScript design patterns?**
  69.    - Common patterns include:
  70.      - **Module Pattern**: Encapsulates code into modules.
  71.      - **Singleton**: Ensures a class has only one instance.
  72.      - **Observer**: Allows objects to subscribe to events.
  73.      - **Factory**: Creates objects without specifying the exact class.
  74.  
  75. 9. **What is the difference between `setTimeout`, `setImmediate`, and `process.nextTick`?**
  76.    - `setTimeout`: Schedules a callback after a minimum delay.
  77.    - `setImmediate`: Executes a callback after the current event loop cycle.
  78.    - `process.nextTick`: Executes a callback immediately after the current operation, before the next event loop tick.
  79.  
  80. 10. **What is referential transparency?**
  81.     - A property of pure functions where the function call can be replaced with its result without changing the program's behavior.
  82.  
  83. 11. **What are the differences between `arguments` object and rest parameter?**
  84.    - `arguments`: Array-like object containing all arguments passed to a function (not available in arrow functions).
  85.    - Rest parameter (`...args`): Actual array containing all remaining arguments.
  86.  
  87. 12. **What are the possible side effects in JavaScript?**
  88.    - Modifying global variables, mutating objects, or performing I/O operations.
  89.  
  90. 13. **What are the phases of execution context?**
  91.    - Creation phase: Variable and function declarations are hoisted.
  92.    - Execution phase: Code is executed line by line.
  93.  
  94. 14. **What is nullish coalescing operator (`??`)?**
  95.    - Returns the right-hand side operand if the left-hand side is `null` or `undefined`.
  96.  
  97. 15. **What is the difference between dense and sparse arrays?**
  98.    - Dense arrays have contiguous elements, while sparse arrays have "holes" (undefined values).
  99.  
  100. 16. **What are the real-world use cases of `Proxy`?**
  101.    - Intercepting and customizing object operations (e.g., validation, logging).
  102.  
  103. 17. **What is the module pattern? What is function composition?**
  104.    - **Module Pattern**: Encapsulates code into reusable modules.
  105.    - **Function Composition**: Combining multiple functions to create a new function.
  106.  
  107. 18. **What are decorators and annotations in JavaScript?**
  108.    - **Decorators**: Functions that modify classes or methods (used with `@` syntax).
  109.    - **Annotations**: Metadata added to code (often used in frameworks like Angular).
  110.  
  111. 19. **Promise.all, Promise.race, Promise.any, Promise.allSettled**
  112.    - `Promise.all`: Resolves when all promises resolve; rejects if any promise rejects.
  113.    - `Promise.race`: Resolves or rejects as soon as one promise settles.
  114.    - `Promise.any`: Resolves as soon as one promise resolves; rejects if all promises reject.
  115.    - `Promise.allSettled`: Resolves after all promises settle, regardless of success or failure.
  116.  
  117. ---
  118.  
  119. ### **React Round**
  120.  
  121. 1. **Describe the flow of data in a Redux application.**
  122.   - Data flows unidirectionally:
  123.     1. User triggers an action.
  124.     2. The action is dispatched to the Redux store.
  125.     3. The store invokes the reducer with the current state and action.
  126.     4. The reducer returns a new state.
  127.     5. The store updates, and React components re-render based on the new state.
  128.  
  129. 2. **Can we use `async` and `await` inside the `useEffect` hooks?**
  130.   - Yes, but you need to define an async function inside `useEffect` and call it:
  131.     ```javascript
  132.     useEffect(() => {
  133.       const fetchData = async () => {
  134.         const result = await someAsyncFunction();
  135.         // Handle result
  136.       };
  137.       fetchData();
  138.     }, []);
  139.     ```
  140.  
  141. ---
  142.  
  143. Let me know if you need further clarification on any of these topics!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement