🚀 JavaScript: Spread vs Rest Both use the same symbol ... but behave differently. Spread → expands values const user = { name: "Priya" }; const updatedUser = { ...user, role: "Developer" }; console.log(updatedUser); // { name: "Priya", role: "Developer" } Rest → collects remaining values const { name, ...rest } = { name: "Priya", role: "Developer", city: "Delhi" }; console.log(rest); // { role: "Developer", city: "Delhi" } Easy way to remember: Spread → Expand values Rest → Collect remaining values #javascript #developer #interviewprepration #javascriptinterview #frontenddeveloper #frontendrole #explore #React #reactjs
JavaScript Spread vs Rest Operators
More Relevant Posts
-
Let's dive into a common concept in JavaScript called promises. ❓ What is a promise? A promise is an object that represents the eventful result of an asynchronous operation,either success or failure. Let's think of an non-technical example: 💡 Food order in a restaurant: You place an order ---> pending Food arrives ---> resolved(fulfiled) Order failes--->rejected 💡 Basic Promise example: 𝙘𝙤𝙣𝙨𝙩 𝙥𝙧𝙤𝙢𝙞𝙨𝙚 = 𝙣𝙚𝙬 𝙋𝙧𝙤𝙢𝙞𝙨𝙚((𝙧𝙚𝙨𝙤𝙡𝙫𝙚,𝙧𝙚𝙟𝙚𝙘𝙩) => { 𝙘𝙤𝙣𝙨𝙩 𝙨𝙪𝙘𝙘𝙚𝙨𝙨 = 𝙩𝙧𝙪𝙚; 𝙞𝙛(𝙨𝙪𝙘𝙘𝙚𝙨𝙨) { 𝙧𝙚𝙨𝙤𝙡𝙫𝙚("𝘿𝙖𝙩𝙖 𝙛𝙚𝙩𝙘𝙝𝙚𝙙"); } 𝙚𝙡𝙨𝙚 { 𝙧𝙚𝙟𝙚𝙘𝙩("𝙀𝙧𝙧𝙤𝙧 𝙤𝙘𝙘𝙪𝙧𝙧𝙚𝙙"); } }); 💡 In Modern way we can handle/resolve a promise is using async/await: 𝐚𝐬𝐲𝐧𝐜 𝐟𝐮𝐧𝐜𝐭𝐢𝐨𝐧 𝐟𝐞𝐭𝐜𝐡𝐃𝐚𝐭𝐚() { 𝐭𝐫𝐲 { 𝐜𝐨𝐧𝐬𝐭 𝐫𝐞𝐬𝐮𝐥𝐭 = 𝐚𝐰𝐚𝐢𝐭 𝐩𝐫𝐨𝐦𝐢𝐬𝐞; 𝐜𝐨𝐧𝐬𝐨𝐥𝐞.𝐥𝐨𝐠(𝐫𝐞𝐬𝐮𝐥𝐭); } 𝐜𝐚𝐭𝐜𝐡 (𝐞𝐫𝐫𝐨𝐫) { 𝐜𝐨𝐧𝐬𝐨𝐥𝐞.𝐥𝐨𝐠(𝐞𝐫𝐫𝐨𝐫); } } ⏯️ Use cases: 1)API calls 2) setTimeout/async tasks 3)parallel operations 4)file upload/download 5)database calls #reactjs #reactinterview #react18 #frontendjobs #ReactJS #Node #Frontend #InterviewPreparation #JavaScript #FullStack #WebDevelopment #SoftwareEngineer #Learning #Hiring #Jobs #FresherJobs #TechTalks #Software #MERN #Frontend #JavaScript #React #CodingInterview #SoftwareEngineering #WebDevelopment
To view or add a comment, sign in
-
[ Here's what you need to know about the JavaScript Event Loop ] Most JavaScript developers use async code every day. But if you ask them what actually happens under the hood... silence. JavaScript is single-threaded. It does ONE thing at a time. Yet it handles async operations without freezing the entire page. Uhkay... BUT, How? The Event Loop existence is the guy behind it. There are 4 layers you need to understand: 1 - Call Stack Where your code actually executes — one line at a time. It only receives things that are ALREADY resolved and ready to run. 2 - Web APIs Where async tasks go to wait. setTimeout, fetch, event listeners — they all leave the Call Stack and sit here while they process. 3 - Callback Queue When a Web API task finishes, it pushes its callback here. The Event Loop picks it up only when the Call Stack is empty. 4 - Microtask Queue Same idea — but for Promises. And it has HIGHER priority than the Callback Queue. The order of execution is always: Call Stack → Microtask Queue (Promises) → Callback Queue (setTimeout, etc.) This is why this code might surprise you: console.log("1"); setTimeout(() => console.log("2"), 0); Promise.resolve().then(() => console.log("3")); console.log("4"); // Output: 1, 4, 3, 2 Even with 0ms delay, setTimeout runs LAST. Because it goes through the Callback Queue — and Promises (Microtask Queue) always go first. The key insight interviewers love to hear: "When a callback finally reaches the Call Stack, the work is already done. The Web API handled the heavy lifting. The Call Stack only receives results — never waiting tasks." This is one of the most asked JavaScript fundamentals in technical interviews. And most candidates get it half right. #javascript #webdevelopment #frontend #programming #technicalinterview
To view or add a comment, sign in
-
🚀 Understanding "pipe()" in RxJS (Angular Developers Must Know!) If you’re working with Angular, you’ve definitely seen "pipe()" everywhere — but what exactly does it do? 🤔 👉 "pipe()" is used to chain multiple RxJS operators to process and control data streams in a clean and readable way. Think of it like a pipeline: Raw Data → Filter → Transform → Final Output 💡 Why "pipe()" is important? ✅ Combine multiple operators ✅ Transform API responses ("map") ✅ Filter unwanted data ("filter") ✅ Handle async flows ("switchMap", "debounceTime") ✅ Manage errors ("catchError") 🧠 Basic Syntax: observable.pipe( operator1(), operator2(), operator3() ) ⚡ Real-world Example (Search API): this.searchInput.valueChanges.pipe( debounceTime(300), filter(value => value.length > 2), switchMap(value => this.http.get(`/api?q=${value}`)) ).subscribe(result => console.log(result)); 👉 This will: - Wait for user typing ⏳ - Avoid unnecessary API calls 🚫 - Always return latest result 🔄 🎯 Key Insight: "pipe()" itself doesn’t modify data — operators inside it do the magic ✨ 🔥 Pro Tip: Master these operators to level up: "map | filter | switchMap | debounceTime | catchError | take" #Angular #RxJS #WebDevelopment #Frontend #JavaScript #Developers #Coding #Tech #Learning #SoftwareEngineering
To view or add a comment, sign in
-
-
💡 JavaScript Essentials: Closures & Hoisting Explained Simply If you're working with JavaScript, especially in frameworks like Angular or React, understanding closures and hoisting is a must. Here’s a quick breakdown 👇 🔹 Closures A closure is created when a function remembers its outer scope even after that outer function has finished execution. 👉 Why it matters? Helps in data encapsulation Used in callbacks, event handlers, and async code Powers concepts like private variables Example: function outer() { let count = 0; return function inner() { count++; console.log(count); } } const counter = outer(); counter(); // 1 counter(); // 2 🔹 Hoisting Hoisting is JavaScript’s behavior of moving declarations to the top of their scope before execution. 👉 Key points: var is hoisted and initialized with undefined let and const are hoisted but stay in the Temporal Dead Zone Function declarations are fully hoisted Example: console.log(a); // undefined var a = 10; console.log(b); // ReferenceError let b = 20; 🚀 Takeaway Closures help you retain state, while hoisting explains how JavaScript reads your code before execution. Mastering these will level up your debugging skills and help you write cleaner, predictable code. #JavaScript #WebDevelopment #Frontend #Angular #React #Coding #Developers
To view or add a comment, sign in
-
𝐄𝐯𝐞𝐧𝐭 𝐋𝐨𝐨𝐩 𝐢𝐧 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭: So event loop is javascript is a mechanism that handles async operations by moving tasks from queue to call stack when it is empty. 𝐒𝐨 𝐰𝐡𝐲 𝐭𝐡𝐞 𝐡𝐞𝐜𝐤 𝐢𝐭 𝐞𝐯𝐞𝐧 𝐞𝐱𝐢𝐬𝐭?? JavaScript is single threaded. So it can run one thing at a time.But we as a developers still do: API calls,setTimeout,Promises. So,event loop helps managing these async tasks. 𝐂𝐨𝐫𝐞 𝐂𝐨𝐧𝐜𝐞𝐩𝐭𝐬: Call Stack:Where code executes,LIFO Web APIs(Browser): Handles async tasks(setTimeout,fetch,etc) Callback Queue(Macrotask Queue): Stores callbacks from setTimeout,setInterval. Microtask Queue : Stores Promise callbacks (.then,catch,await) Event Loop: Moves tasks to stack when it's empty 𝐄𝐱𝐚𝐦𝐩𝐥𝐞: console.log("Start"); setTimeout(()=>{ console.log("Timeout"); }) Promise.resolve().then(()=>{ console.log("Promise") }) console.log("End"); Console log : Start ,End , Promise , Timeout Start → sync → printed setTimeout → goes to Web API Promise → goes to microtask queue End → sync → printed Now stack is empty. Event loop runs: Microtasks → Promise Macrotasks → Timeout #reactjs #reactinterview #react18 #frontendjobs #ReactJS #Node #Frontend #InterviewPreparation #JavaScript #FullStack #WebDevelopment #SoftwareEngineer #Learning #Hiring #Jobs #FresherJobs #TechTalks #Software #MERN #Frontend #JavaScript #React #CodingInterview #SoftwareEngineering #WebDevelopment
To view or add a comment, sign in
-
#js #5 **Truthy and Falsy Values in JavaScript** In JavaScript, values are treated as either truthy or falsy when used in conditions (like in if statements). -Falsy Values Definition: Falsy values are values that are considered false when converted to a boolean. 👉 There are only a few falsy values: false 0 "" (empty string) null undefined NaN Example: if (0) { console.log("This will NOT run"); } else { console.log("0 is falsy"); } -Truthy Values Definition: Truthy values are all values that are considered true when converted to a boolean. 👉 Almost everything else is truthy: Non-zero numbers (1, -5, etc.) Non-empty strings ("hello") Arrays ([]) Objects ({}) true Example: if ("hello") { console.log("This will run"); } -Example Comparison console.log(Boolean(0)); // false console.log(Boolean("Hi")); // true console.log(Boolean(null)); // false console.log(Boolean(100)); // true #Javascript #ObjectOrientedProgramming #SoftwareDevelopment
To view or add a comment, sign in
-
🚀 The #1 Most Asked Angular Interview Question: "What's the difference between switchMap, mergeMap, concatMap, and exhaustMap?" 🤔 If you've ever mapped an HTTP request inside an RxJS stream and ended up with an `Observable<Observable<Data>>`, you've hit the Higher-Order Observable Nightmare! Understanding these 4 Concurrency Operators separates the junior developers from the Senior Engineers. Here is my ultimate visual cheat sheet: 1️⃣ switchMap (The Canceller) 🔪 - Perfect for search inputs. It instantly cancels old, pending requests. 2️⃣ mergeMap (The Multi-Tasker) 🚀 - Perfect for firing off parallel requests where order doesn't matter. 3️⃣ concatMap (The Queuer) ⏳ - Perfect for strict, step-by-step sequential API calls. 4️⃣ exhaustMap (The Ignorer) 🛑 - Perfect for "Pay Now" buttons to completely ignore spam clicks! Swipe through the carousel 👇 for full visual marble diagrams and code examples of each! Which operator do you end up using the most? Let me know in the comments! 👇 #Angular #RxJS #WebDevelopment #Frontend #JavaScript #TechTips #SoftwareEngineering #AbidAnsari
To view or add a comment, sign in
-
🚀 Using Local Storage API (JavaScript) The Local Storage API provides methods for setting, getting, and removing data. `localStorage.setItem(key, value)` stores a key-value pair, `localStorage.getItem(key)` retrieves the value associated with a key, and `localStorage.removeItem(key)` removes a key-value pair. `localStorage.clear()` removes all data stored in Local Storage for the origin. The values are stored as strings, so you may need to use `JSON.stringify()` and `JSON.parse()` to store and retrieve complex data structures. #JavaScript #WebDev #Frontend #JS #professional #career #development
To view or add a comment, sign in
-
-
🚨 Angular Trick Question That Even Experienced Devs Fail! Let’s see if you can crack this 👇 ❓ Question: What will be the output of this code? @Component({ selector: 'app-root', template: `{{value}}` }) export class AppComponent { value = 0; ngOnInit() { setTimeout(() => { this.value = 10; }, 0); Promise.resolve().then(() => { this.value = 20; }); } } 👇 Think before you answer… --- 💥 Most common answers: 👉 10 👉 30 👉 Depends on timing ❌ All WRONG (or incomplete) --- 💡 Correct Answer: 20 🔥 Why? Because of JavaScript Event Loop + Microtask Queue 🔹 "Promise.then()" → goes to microtask queue 🔹 "setTimeout()" → goes to macrotask queue 👉 Microtasks ALWAYS execute before macrotasks So execution order: 1. "Promise.then()" → sets value = 20 2. "setTimeout()" → sets value = 10 (but Angular change detection already ran) ⚡ Angular detects change after microtask → UI shows 20 --- 🧠 Real Insight: This is why async bugs in Angular are tricky — it’s not just Angular, it’s how JS works under the hood. 🔥 Comment your answer before reading others 👀 Let’s see who actually understands this deeply #Angular #JavaScript #Frontend #CodingInterview #WebDev #RxJS #AngularTips
To view or add a comment, sign in
-
Recently in an interview, I was asked about the JavaScript Event Loop… I thought I knew it — but explaining it clearly was harder than expected. So I created this diagram to understand it properly 👇 • Understanding JavaScript Event Loop (Simple Explanation) ° JavaScript Engine JavaScript runs on a single thread. It uses: • Memory Heap → to store data • Call Stack → to execute code 📞 Call Stack All synchronous code runs here. Functions are pushed and popped one by one. 🌐 Web APIs (Browser / Node.js) Async operations are handled outside the JS engine: • setTimeout / setInterval • fetch API • DOM events These APIs run in the background. 📥 Queues Once async work is done, callbacks go into queues: 👉 Microtask Queue (High Priority) • Promise.then() • async/await 👉 Task Queue (Low Priority) • setTimeout • setInterval • DOM events 🔁 Event Loop (Most Important Part) The event loop keeps checking: Is Call Stack empty? Execute ALL Microtasks Then execute ONE Task from Task Queue That’s why Promises run before setTimeout! One Line Summary: JavaScript uses Call Stack + Web APIs + Queues + Event Loop to handle async code without blocking execution. This is one of the most common interview questions — but also one of the most misunderstood. If you can explain this clearly, you’re already ahead of many developers. #JavaScript #EventLoop #AsyncJavaScript #WebDevelopment #NodeJS #Frontend #Programming #Interview
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development