JavaScript Concept: What is Tree Shaking? Answer: Tree Shaking removes unused code from your bundle. Example: import { add } from "./utils" If other functions are unused, they won’t be included. Explanation: Bundlers like: • Webpack • Vite • Rollup analyze imports and remove dead code. Benefits: 1. smaller bundle size 2. faster load time 3. better performance Important: Tree shaking works best with ES modules (import/export). Follow-up: Have you checked your bundle size recently? #javascript #WebPerformance #FrontendOptimization
Tree Shaking: Remove Unused Code from Your Bundle
More Relevant Posts
-
Most developers get confused by the JavaScript Event Loop 🤯 Here’s the simplest way to understand it: JavaScript is single-threaded — it runs one task at a time. But async tasks (setTimeout, API calls, promises) don’t block the code. 👉 They go to Web APIs (handled by browser) 👉 Then move to a Queue 👉 Event Loop pushes them back when the stack is empty Example: console.log("Start") setTimeout(() => console.log("Timeout"), 0) console.log("End") Output: Start End Timeout Even 0ms delay runs last 😲 Bonus: Promises run before setTimeout because they use Microtask Queue ⚡ Have you struggled with Event Loop before?
To view or add a comment, sign in
-
-
💡 JavaScript Practice — Counting Vowels A small problem, but a good test of logic: 👉 Count the number of vowels in a string Here’s my solution: const str = "javascript"; const vowels = "aeiouAEIOU"; let count = 0; for (let letter of str) { for (let vowel of vowels) { if (letter === vowel) count++; } } console.log(count); 🧠 What this taught me: • How nested loops actually work in real scenarios • Breaking a problem into smaller steps • Writing simple, readable logic ⚡ Next step: I’ll try optimizing this (maybe using includes() or a better approach) If you have a cleaner or more efficient solution, I’d love to see it. #JavaScript #ProblemSolving #WebDevelopment #LearningInPublic
To view or add a comment, sign in
-
🧠 Day 3 of 21 days challenge JavaScript Event Loop 🤯 Event Loop is a mechanism in JavaScript that handles execution of asynchronous code. It continuously checks the call stack and callback queue. If the stack is empty, it moves tasks from the queue to the stack for execution. For example :- console.log("Start"); console.log("End"); console.log("Timeout"); Wait… why this order? Because JavaScript doesn’t run everything instantly. It uses: • Call Stack • Web APIs • Callback Queue Event Loop decides what runs next. 💤For easy understanding :- Event Loop = decides execution order Sync code runs first Async code waits in queue Then runs after the stack is empty 👉 That’s why “Timeout” runs last This changed how I understand async code 🚀 #JavaScript #EventLoop #Async
To view or add a comment, sign in
-
-
JavaScript Event Loop — simplified 👇 Understanding this changed how I debug async code. ▪️ Call Stack handles execution ▪️ Web APIs handle async tasks ▪️ Event Loop manages flow ▪️ Microtasks (Promises) run before callbacks ⚡ Once this clicks, JavaScript becomes much easier. What’s the most confusing part of JS for you? #JavaScript #FrontendDevelopment #WebDevelopment
To view or add a comment, sign in
-
-
Day 13/100 of JavaScript Missed a day, but continuing the streak Today’s topic: Call Stack and Event Loop JavaScript is single-threaded, which means it executes one task at a time using a call stack - Call Stack → manages function execution (LIFO) - Functions are pushed when called and popped after execution For asynchronous operations, JavaScript uses: - Web APIs - Callback Queue / Microtask Queue - Event Loop Example: console.log("Start"); setTimeout(() => { console.log("Timeout"); }, 0); console.log("End"); Output: Start End Timeout Even with 0 delay, "setTimeout" executes later because it goes through the event loop The event loop ensures asynchronous tasks are executed only when the call stack is empty No matter the delay, consistency continues #Day13 #JavaScript #100DaysOfCode
To view or add a comment, sign in
-
Javascript: Undefined vs null Ever seen undefined and null in JavaScript and felt confused? 🤔 You’re not alone. Many beginners mix them up. But the difference is actually very simple. Here’s the easy way to understand it: • undefined → A variable is declared but no value is assigned yet let name; console.log(name); // undefined • null → A developer intentionally sets an empty value let user = null; • undefined is automatic – JavaScript gives it by default. • null is intentional – The developer sets it manually. • Both mean “no value”, but the reason is different. Simple rule to remember: 👉 undefined = not assigned yet 👉 null = intentionally empty Understanding this small concept can help you avoid many bugs in JavaScript. #JavaScript #WebDevelopment #FrontendDevelopment #ProgrammingTips #LearnJavaScript #CodingForBeginners #SoftwareEngineering #TechEducation #JavaScriptDeveloper #DevCommunity
To view or add a comment, sign in
-
-
I built a browser-based code playground. Write HTML, CSS, and JavaScript on the left. See the result instantly on the right. No frameworks. No build tools. Just vanilla JavaScript. What it does: • Real-time preview as you type • Auto-saves your code • Tab key support for faster coding Live demo: https://lnkd.in/eXrHsNS2 #JavaScript #WebDevelopment #CodingTools Or even shorter: text Just shipped: Live Code Playground Write code → see results instantly. Auto-saves. Zero dependencies. Pure JS. Try it https://lnkd.in/eXrHsNS2
To view or add a comment, sign in
-
𝗖𝗿𝗮𝗰𝗸 𝘁𝗵𝗲 𝗖𝗼𝗱𝗲: 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗛𝗼𝗶𝘀𝘁𝗶𝗻𝗴 𝗘𝘅𝗽𝗹𝗮𝗶𝗻𝗲𝗱! 🤔 Ever seen code that works even though you call a function before defining it? That's the magic (and potential trap) of Hoisting! 🪄 Here is a simple breakdown of this essential JS concept: What is it? Think of it as the JavaScript engine giving your declarations a "lift." Before running your code, it moves function and variable declarations (not their values!) to the top of their scope. ⬆️ 𝗩𝗮𝗿𝗶𝗮𝗯𝗹𝗲𝘀 𝘄𝗶𝘁𝗵 𝘃𝗮𝗿: These are hoisted and initialized to undefined. You can access them, but they won't have their values yet. 🤷♂️ 𝗩𝗮𝗿𝗶𝗮𝗯𝗹𝗲𝘀 𝘄𝗶𝘁𝗵 𝗹𝗲𝘁 & 𝗰𝗼𝗻𝘀𝘁: These are hoisted but not initialized. Accessing them before they're defined throws an error—a safe space known as the Temporal Dead Zone (TDZ)! 🛑🚫 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻𝘀: Full function declarations are hoisted, allowing you to call them anywhere in their scope. (This is super convenient!) 🤩 Understanding hoisting is crucial for avoiding confusing bugs and writing cleaner, more predictable code. 🧱💻 Check out this diagram for a visual guide! #JavaScript #WebDevelopment #CodingTips #SoftwareEngineering #Hoisting #TemporalDeadZone #LearningToCode #WebDev
To view or add a comment, sign in
-
-
JavaScript performance tip: Use const and let instead of var. Why? → Block scoping prevents bugs → const signals immutability → Better for JS engines to optimize Small syntax change. Big impact on code quality. #JavaScript #BestPractices #Performance
To view or add a comment, sign in
-
💡 Pure vs Impure Functions in JavaScript 🔹 Pure Function Same input → Same output. No side effects. const add = (a, b) => a + b; 🔸 Impure Function Depends on or changes external state. let total = 0; const addToTotal = (v) => total += v; 🚀 Why it matters? Predictable code. Easier testing. Fewer bugs. 👉 Write pure functions whenever possible. #JavaScript #CleanCode #FunctionalProgramming
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