TypeScript Tip: The ??= Operator Just learned about the Nullish Coalescing Assignment operator ( ??=) while building a logger utility! example would be this: long hand: if (singleton === null || singleton === undefined) { singleton = initLogger(); } You can write this: short hard: singleton ??= initLogger(); Perfect for: Singleton patterns ,Lazy initialization ,Default values , Caching strategies The beauty? It only assigns if the value is null or undefined, not for other falsy values like 0 or "". #TypeScript #JavaScript #WebDev #CleanCode
TypeScript Nullish Coalescing Assignment Operator
More Relevant Posts
-
Memoization is a powerful tool but misusing it creates: • Extra memory usage • More dependency comparisons • Harder debugging • Zero real performance gains Optimization without profiling is just assumption. Use React DevTools. Find the real bottleneck. Fix what actually matters. For more information contact : https://lnkd.in/gNan5xMQ #ReactJS #FrontendDevelopment #WebDevelopment #JavaScript #ReactDeveloper #SoftwareEngineering #PerformanceOptimization #CleanCode #FrontendEngineer #TechLeadership #ProgrammingTips
To view or add a comment, sign in
-
Most TypeScript bugs I see in production start with one word: "any". Avoid using < any > to "move faster". It almost always slows you down later. If you don’t know the type yet, use < unknown >. Why? Because < unknown > forces you to prove what the value is before you use it. < any > just lets bugs walk straight into production. Rule of thumb: – < any > = silence the compiler – < unknown > = work with the compiler The moment I switched to < unknown > by default, my error handling became clearer and my runtime bugs dropped noticeably. Do you still reach for < any > - or did you make the switch? #TypeScript #JavaScript #Frontend #WebDevelopment
To view or add a comment, sign in
-
-
🔴 Stop using any in TypeScript Why any is bad: ❌ Removes type safety ❌ Can hide bugs Why unknown is better: ✅ Makes you check the type first ✅ Keeps your code safe Quick rule: If you want to use any, ask: “Do I really not know the type, or am I just taking a shortcut 😕?” 💡 Most of the time, unknown is the better option. #TypeScript #JavaScript #WebDevelopment #SoftwareEngineering
To view or add a comment, sign in
-
✨ What is a 𝗧𝗿𝗮𝗻𝘀𝗽𝗶𝗹𝗲𝗿 used for in #JavaScript? A transpiler (source-to-source compiler) takes modern JavaScript code (ES6+, ESNext) and converts it into older, widely supported JavaScript (usually ES5). The most popular example is Babel – it lets us write clean arrow functions, classes, async/await, optional chaining and more… while still running perfectly in older browsers and environments. Do you already use a transpiler (consciously :D) in your workflow? Share in the comments! #CleanCodeSolutions #WebDevelopment #JavaScript #Babel
To view or add a comment, sign in
-
-
In DevOps we work a lot with YAML. But YAML only describes data. The meaning lives entirely in the controllers that consume it. Concrete example: A GitOps notification messageTemplate references .Updated.Changes. After a controller upgrade the field becomes .Changed.Changes. The YAML is still valid and the intent is unchanged but CI fails because the internal data model changed. Tools like Helm or Kustomize render YAML, but they don’t protect intent when controller internals or template fields evolve. We have no real transpilers that adapt old intent to new controller versions. Similar to how Babel outputs JS for a specific runtime, treating YAML more like compiled output instead of static config would save a lot of pain. Until then, logs help us bridge the gap. 😂 #DevOps #GitOps #FluxCD #CI #BonnConsulting
✨ What is a 𝗧𝗿𝗮𝗻𝘀𝗽𝗶𝗹𝗲𝗿 used for in #JavaScript? A transpiler (source-to-source compiler) takes modern JavaScript code (ES6+, ESNext) and converts it into older, widely supported JavaScript (usually ES5). The most popular example is Babel – it lets us write clean arrow functions, classes, async/await, optional chaining and more… while still running perfectly in older browsers and environments. Do you already use a transpiler (consciously :D) in your workflow? Share in the comments! #CleanCodeSolutions #WebDevelopment #JavaScript #Babel
To view or add a comment, sign in
-
-
𝗪𝗲𝗹𝗰𝗼𝗺𝗲 𝘁𝗼 𝗗𝗮𝘆 𝟭𝟲 JavaScript is single-threaded. So how can it handle: • Synchronous code • Promises • Timers All at the same time? The answer is task priority and the Event Loop. In this video, I demonstrate exactly how tasks are added and executed based on priority. 𝙒𝙝𝙚𝙣 𝙘𝙤𝙙𝙚 𝙧𝙪𝙣𝙨: -> Code executes first (Call Stack). -> Promise callbacks go to the Microtask Queue. -> setTimeout callbacks go to the Macrotask Queue. 𝙃𝙤𝙬 𝙩𝙝𝙚 𝙀𝙫𝙚𝙣𝙩 𝙇𝙤𝙤𝙥 𝙋𝙞𝙘𝙠𝙨 𝙏𝙖𝙨𝙠𝙨 When the Call Stack becomes empty: -> Run ALL microtasks (Promises first). -> Then run ONE macrotask (setTimeout). -> Repeat the cycle. Microtasks always have higher priority. 𝙏𝙝𝙞𝙨 𝙥𝙧𝙞𝙤𝙧𝙞𝙩𝙮 𝙨𝙮𝙨𝙩𝙚𝙢 𝙞𝙨 𝙬𝙝𝙖𝙩 𝙖𝙡𝙡𝙤𝙬𝙨 𝙅𝙖𝙫𝙖𝙎𝙘𝙧𝙞𝙥𝙩 𝙩𝙤: • Stay responsive • Execute async logic predictably • Simulate concurrency while staying single-threaded #JavaScript #WebDevelopment #FrontendDevelopment #EventLoop #AsyncJavaScript #SoftwareEngineering #DeveloppementWeb #JavaScriptFR
To view or add a comment, sign in
-
🟢 Day 17 / 100 – 📌JavaScript Practice 🚀 ✅ Practiced nested arrays using a Tic-Tac-Toe board today. ✅Explored how indexing works in JavaScript by accessing valid, invalid, and negative indexes through the console. • Learned - Errors and undefined values help in understanding how JavaScript actually behaves under the hood. #Day17 #JavaScript #WebDevelopment #FrontendDevelopment
To view or add a comment, sign in
-
-
Why Arrow Functions were introduced in JavaScript 🚀 Cleaner syntax, lexical this, implicit returns, and fewer surprises compared to traditional function declarations. Understanding why something exists makes you a better developer—not just a faster one. 💡 #JavaScript #WebDevelopment #Frontend #ES6 #CodingConcepts
To view or add a comment, sign in
-
-
Today I spent time deeply understanding JavaScript closures and it turned out to be really interesting. Here are a few key takeaways: 1. An inner function can access variables from its outer function 2. Even after the outer function has finished execution, the inner function still holds a reference to those variables 3. If closures are not used properly, they can lead to memory leaks and performance issues, especially under heavy load #JavaScript #Closures #FrontendDevelopment #LearningInPublic #WebDevelopment
To view or add a comment, sign in
-
-
Most developers avoid reduce() because it looks confusing. But once you understand it, your code becomes cleaner, smarter, and powerful ⚡ reduce() lets you turn an array into a single value — sum, average, object, anything. Learn it once. Use it everywhere. 💡 #JavaScript #WebDevelopment #FrontendDeveloper #CodingTips #JSBasics #LearnToCode
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