TGViewer
Web Development - HTML, CSS & JavaScript Web Development - HTML, CSS & JavaScript @javascript_courses · 55.7K subscribers
Post #3169 7.81K
✅ Top Javascript Interview Questions with Answers: Part-4 💻✨

31. What is a rest parameter? 
Rest parameter (...args) allows a function to accept an indefinite number of arguments as an array. 
function sum(...numbers) {
  return numbers.reduce((a, b) => a + b, 0);
}
console.log(sum(1, 2, 3)); // 6


32. What are template literals? 
Template literals use backticks (`) to embed variables and expressions. 
const name = 'Alice';
console.log(Hello, ${name}!); // Hello, Alice!


33. What is a module in JS? 
Modules help organize code into reusable files using export and import. 
// file.js
export const greet = () => console.log('Hi');

// main.js
import { greet } from './file.js';
greet();


34. Difference between default export and named export 
• Default export: One per file, imported without {}
• Named export: Multiple exports, must use the same name
// default export
export default function() {}
import myFunc from './file.js';

// named export
export const x = 5;
import { x } from './file.js';


35. How do you handle errors in JavaScript? 
Use try...catch to handle runtime errors gracefully. 
try {
  JSON.parse("invalid json");
} catch (error) {
  console.log("Caught:", error.message);
}


36. What is the use of try...catch? 
To catch exceptions and prevent the entire program from crashing. It helps with debugging and smoother user experience.

37. What is a service worker? 
A script that runs in the background of web apps. Enables features like offline access, caching, and push notifications.

38. localStorage vs. sessionStorage 
• localStorage: Data persists after tab/browser close
• sessionStorage: Data clears when the tab is closed
localStorage.setItem('user', 'John');
sessionStorage.setItem('token', 'abc123');


39. What is debounce and throttle? 
• Debounce: Waits for inactivity before running a function
• Throttle: Limits function execution to once per time interval
Used in scroll/input/resize events to reduce overhead.

40. What is the Fetch API? 
Used to make network requests. Returns a Promise. 
fetch('https://api.example.com')
  .then(res => res.json())
  .then(data => console.log(data))
  .catch(err => console.error(err));


💬 Double Tap ❤️ for Part-5!
  • ❤ 27
  • 🔥 3
  • 😁 1
More from @javascript_courses
  1. Oct 9, 2026🇮🇳 𝗚𝗢𝗩𝗘𝗥𝗡𝗠𝗘𝗡𝗧 𝗢𝗙 𝗜𝗡𝗗𝗜𝗔 — 𝗔𝗜𝗖𝗧𝗘 𝗜𝗡𝗧𝗘𝗥𝗡𝗦𝗛𝗜𝗣𝗦 𝟮𝟬𝟮𝟲 🚀…
  2. Oct 8, 2026🎓 𝗠𝗶𝗰𝗿𝗼𝘀𝗼𝗳𝘁 𝗙𝗥𝗘𝗘 𝗖𝗼𝘂𝗿𝘀𝗲𝘀 𝘄𝗶𝘁𝗵 𝗖𝗲𝗿𝘁𝗶𝗳𝗶𝗰𝗮𝘁𝗲𝘀! 🚀🔥 Upgr…
  3. Oct 7, 2026🚀𝗣𝗮𝘆 𝗔𝗳𝘁𝗲𝗿 𝗣𝗹𝗮𝗰𝗲𝗺𝗲𝗻𝘁 𝗧𝗿𝗮𝗶𝗻𝗶𝗻𝗴 | 𝗕𝗲𝗰𝗼𝗺𝗲 𝗮 𝗙𝘂𝗹𝗹𝘀𝘁𝗮𝗰…
  4. Oct 7, 2026𝗠𝗮𝘀𝘁𝗲𝗿 𝗣𝗼𝘄𝗲𝗿 𝗕𝗜 𝗳𝗼𝗿 𝗙𝗥𝗘𝗘! 🔥 Learn Power BI through these FREE learnin…
  5. Oct 4, 2026DSA Handwritten Notes
  6. Sep 28, 2026To learn web design and development from basic to advanced levels, you can follow these st…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →