🧠 JavaScript Module Question for Developers While building my own small utility library, I came across this interesting pattern in ES modules. Consider this structure: src/ ├ array/ │ ├ chunk.ts │ └ index.ts └ index.ts Inside array/index.ts: export * from "./chunk" Inside src/index.ts: export * from "./array" Now a developer imports the function like this: import { chunk } from "tiny-utils" ❓ Question: From which file is the chunk function actually executed? A) src/index.ts B) array/index.ts C) chunk.ts Drop your answer in the comments 👇 and explain why. This pattern is widely used in libraries to create clean APIs and is often called a barrel export pattern. #javascript #typescript #webdevelopment #nodejs #programming #softwareengineering #devcommunity #coding #frontenddevelopment #backenddevelopment
JavaScript Barrel Export Pattern Explained
More Relevant Posts
-
🚀 𝐓𝐲𝐩𝐞𝐒𝐜𝐫𝐢𝐩𝐭 𝐒𝐞𝐫𝐢𝐞𝐬 — 𝐀𝐫𝐭𝐢𝐜𝐥𝐞 𝟎𝟐 𝙇𝙖𝙗𝙚𝙡𝙚𝙙 𝘽𝙤𝙭𝙚𝙨: 𝙐𝙣𝙙𝙚𝙧𝙨𝙩𝙖𝙣𝙙𝙞𝙣𝙜 𝙑𝙖𝙧𝙞𝙖𝙗𝙡𝙚𝙨 𝙖𝙣𝙙 𝘽𝙖𝙨𝙞𝙘 𝙏𝙮𝙥𝙚𝙨 𝙞𝙣 𝙏𝙮𝙥𝙚𝙎𝙘𝙧𝙞𝙥𝙩 𝐕𝐚𝐫𝐢𝐚𝐛𝐥𝐞𝐬 in programming are like boxes that store data. In real life, we use labels to easily identify what’s inside a box, right? Because if a box has a label, it’s easy to understand what’s inside. If it doesn’t, things get confusing. The same concept applies to programming. But in 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭, these boxes don’t have labels. So inside a single JavaScript variable, you can store: 👉 a 𝙣𝙪𝙢𝙗𝙚𝙧 👉 a 𝙨𝙩𝙧𝙞𝙣𝙜 👉 a 𝙗𝙤𝙤𝙡𝙚𝙖𝙣 This flexibility might seem useful… But it’s one of the main reasons behind 𝐫𝐮𝐧𝐭𝐢𝐦𝐞 𝐞𝐫𝐫𝐨𝐫𝐬. 💡 𝐓𝐲𝐩𝐞𝐒𝐜𝐫𝐢𝐩𝐭 solves this problem using 𝙩𝙮𝙥𝙚𝙨. It allows you to add labels to your variables: 👉 If you only need to store 𝙩𝙚𝙭𝙩 inside a variable, you can use the 𝙨𝙩𝙧𝙞𝙣𝙜 type. 👉 If you only need to store 𝙣𝙪𝙢𝙗𝙚𝙧𝙨 inside a variable, you can use the 𝙣𝙪𝙢𝙗𝙚𝙧 type. 👉 If you only need to store 𝙩𝙧𝙪𝙚/𝙛𝙖𝙡𝙨𝙚 inside a variable, you can use the 𝙗𝙤𝙤𝙡𝙚𝙖𝙣 type. By using these types: ✅ Your code becomes safer ✅ Bugs are reduced ✅ Developer experience improves In this article, I explain: 📦 What variables really are 🏷️ How type labels work in TypeScript 🧠 What Type Inference is ⚙️ The role of the TypeScript compiler 📖 Read the full article here: 👉 https://lnkd.in/g725SZP4 #TypeScript #JavaScript #WebDevelopment #Programming #LearningInPublic #SoftwareEngineering🚀
To view or add a comment, sign in
-
-
𝗩𝗮𝗻𝗶𝗹𝗹𝗮 𝗖𝗼𝗱𝗲: 𝗛𝗼𝘄 𝗩𝟴 𝗖𝗼𝗺𝗽𝗶𝗹𝗲𝘀 𝗬𝗼𝘂𝗿 𝗖𝗼𝗱𝗲 You spend your days working with JavaScript. But have you ever wondered what happens behind the scenes? When you run your code, V8 - the JavaScript engine - takes over. It's not just a compiler, it's a performance expert. Here's how it works: - V8 reads your code as a stream of characters - It builds a blueprint, called the Abstract Syntax Tree (AST) - V8 is lazy, so it only builds the full AST when needed - It uses an interpreter, called Ignition, to turn the AST into bytecode - Bytecode is like stage directions for your code When your code runs, V8 watches and takes notes. It looks for hot paths - loops that run many times. When it finds them, it uses Sparkplug to compile the bytecode to machine code. If a function is super hot, V8 uses Maglev to create a baseline optimized version. For critical code, V8 uses TurboFan, an optimizing compiler. TurboFan makes a bet: it assumes your code will keep doing what it's doing. If you keep passing it the same types, your code runs fast. But if you change the type, V8 falls back to the slower bytecode. To keep V8 happy, write consistent code. Use consistent types, small functions, and avoid deleting properties. JavaScript is not slow - your misuse of it is. V8 is a masterpiece of engineering. It's a Just-In-Time compiler that does adaptive optimization. When you write code, you're feeding an algorithm. Understand how it thinks, and you'll stop fighting the machine. Source: https://lnkd.in/g4Fkem6a
To view or add a comment, sign in
-
JavaScript Closures Explained Complete Notes for Developers Closures are one of the most powerful and important concepts in JavaScript. They allow a function to access variables from its outer scope even after the outer function has finished executing. Understanding closures helps you master data privacy, function factories, callbacks, and advanced patterns used in modern frameworks like React. These notes break down closures in a simple and practical way with clear explanations and real-world use cases to strengthen your core JavaScript knowledge. If closures confuse you, your JavaScript fundamentals are weak. #JavaScript #Closures #JSConcepts #WebDevelopment #FrontendDevelopment #LearnJavaScript #Programming #DeveloperNotes #Coding #SoftwareEngineering
To view or add a comment, sign in
-
JavaScript Array Methods Every Developer Should Know 👨💻 Arrays are one of the most commonly used data structures in JavaScript. When you understand array methods well, your code becomes cleaner, shorter, and easier to maintain. Here are some important methods every developer should know: 🔹 map() – Transforms each element in an array and returns a new array. 🔹 filter() – Selects elements that match a specific condition. 🔹 reduce() – Converts the entire array into a single value (great for totals, counts, and data processing). 🔹 find() – Returns the first element that matches a condition. 🔹 some() – Checks if at least one element satisfies a condition. 🔹 every() – Checks if all elements satisfy a condition. Mastering these methods helps you write more efficient JavaScript and improves your problem-solving skills in real projects. Which JavaScript array method do you use the most? 🤔 #JavaScript #WebDevelopment #FrontendDeveloper #Coding #Programming #100DaysOfCode
To view or add a comment, sign in
-
-
🔗 Read the blog – Click here to explore: https://lnkd.in/giZieFvj 🚀 Just published a new blog on JavaScript Modules (Import & Export) JavaScript modules help in organizing code by splitting it into smaller, reusable files, making applications easier to manage and scale. In this blog: 📦 What modules are 📤 How export works 📥 How import works 🔄 Default vs Named exports 🧠 Simple diagrams for easy understanding This concept is very important for building real-world applications and writing clean code. 🙏 Special thanks to 👉 Hitesh Choudhary Sir 👉 Piyush Garg Sir 👉Chai Aur Code for teaching and helping in understanding these concepts clearly. #JavaScript #WebDevelopment #NodeJS #Frontend #Coding #Programming #LearnToCode
To view or add a comment, sign in
-
-
Prototypes in JavaScript (The Secret Behind Everything) JavaScript doesn’t use classical inheritance like Java or C++ 👉 It uses Prototypal Inheritance --- 💡 Every object in JS has a hidden link: "[[Prototype]]" --- ⚡ Example: const animal = { speak() { console.log("Animal speaks"); } }; const dog = Object.create(animal); dog.speak(); // 🐶 Animal speaks --- 🤯 What just happened? - "dog" does NOT have "speak()" - JavaScript looks into its prototype - Finds it in "animal" 👉 This is called the Prototype Chain --- 🧩 Real Magic: [].map === Array.prototype.map // true 👉 That’s why arrays have methods like "map", "filter", etc. --- ⚠️ Important: dog.__proto__ === animal // true But avoid using "__proto__" directly Use "Object.getPrototypeOf()" --- 🚀 Why this matters: - Foundation of JS inheritance - Helps understand classes under the hood - Makes debugging easier --- Reference from 👉 Sheryians Coding School #javascript #webdevelopment #frontend #programming #coding
To view or add a comment, sign in
-
-
Node.js is more than just JavaScript on the server. Behind the scenes it combines V8 Engine, C++ bindings, and libuv to deliver an event-driven, non-blocking architecture capable of handling thousands of concurrent requests. Understanding these internals helps developers build high-performance and scalable backend systems. Grateful for the continuous guidance from Hitesh Choudhary Sir, Piyush Garg Sir for guiding this learning journey. #NodeJS #BackendDevelopment #JavaScript #SystemDesign #SoftwareEngineering #DevCommunity #EventLoop #V8Engine #chaicode https://lnkd.in/gfrMmZ-T
To view or add a comment, sign in
-
📣 𝗡𝗲𝘅𝘁 𝗕𝗹𝗼𝗴 𝗶𝘀 𝗛𝗲𝗿𝗲! ⤵️ Understanding Object-Oriented Programming in JavaScript 🧩💻 One of the most important programming concepts—explained in simple, beginner-friendly terms. 🔗 𝗥𝗲𝗮𝗱 𝗵𝗲𝗿𝗲: https://lnkd.in/gvH9UgXb 𝗧𝗼𝗽𝗶𝗰𝘀 𝗰𝗼𝘃𝗲𝗿𝗲𝗱 ✍🏻: ⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺ ⇢ What Object-Oriented Programming really means ⇢ Why real programs need objects ⇢ Class vs Object (blueprint vs real instance) ⇢ How constructors initialize data ⇢ Adding methods (behavior inside objects) ⇢ Encapsulation in simple terms ⇢ Organizing code for scalability ⇢ How OOP makes large applications manageable 💬 If you’re starting with JavaScript or trying to understand how real applications are structured, this will help you build a strong foundation. #ChaiAurCode #JavaScript #OOP #WebDevelopment #100DaysOfCoding
To view or add a comment, sign in
-
-
JavaScript Doesn't Have Classes! Yes, that's correct. Anyone who started using JavaScript after 2015 will be very confused by this statement. "But I saw the class syntax in the intro course I took when I started programming!" Which would also be accurate. JavaScript has a syntax for classes, but under the hood, no class in the Java/C++ sense is being declared. Don't believe me? Go run this in your browser console: class Test { constructor() { this.prop = "test"; } } console.log(typeof Test); Yes, it's a function. JavaScript classes essentially do two things: create a constructor function that works with the "new" keyword, and set up a prototype object (more on that another time). "Okay, but it's still basically a class." No, not really. Try this code (hopefully you tried the one above first): let x = new Test(); Now you have a Test object with one property, "prop". Now do this: x.newprop = "newprop"; This runs. In most other languages, this would be grounds for the compiler to crash your IDE out of pure spite. It runs in JavaScript because the class was never acting as a blueprint, it was just a special constructor function all along. If you've always been confused by the __proto__ property when checking Javascript objects and too scared to ask what it is, well it's part of the same conspiracy, I will be writing about it in my next post #javascript #webdevelopment #programming
To view or add a comment, sign in
-
-
To understand the depth of Rust, you must look at how it manages memory at the hardware level. In JavaScript, every object is a heavy structure stored in the heap memory, requiring a Garbage Collector to constantly scan and clean it up. Rust replaces this with a much faster system that separates data from behavior. You define your data using an Enum, which is stored directly on the stack for instant access. You then use an impl block to define the logic separately. This means the computer only loads the instructions when they are specifically called, rather than carrying a bulky object around in the RAM at all times. When you write an implementation for fmt::Display, you are fulfilling a Trait. In systems programming, a Trait is a strict professional contract. The Display trait is a set of rules from the standard library that tells the compiler exactly how your data should be translated into text. Because this is a Compile Time guarantee, the Rust compiler checks every detail before the program even runs. If your function does not match the required signature perfectly, the code will not compile. This eliminates the common runtime errors and crashes found in higher level languages like JavaScript. The power of this system lies in the function arguments &self and &mut f. These are not just variables they are instructions for the Borrow Checker, which is the heart of Rust safety. The &self parameter is an Immutable Borrow, meaning you are looking at the data exactly where it lives in memory without making a copy. The f parameter is the Formatter, a specialized tool that streams text to the output. By using &mut, you are taking a Mutable Borrow, which gives you exclusive temporary permission to change the formatter. Rust laws forbid any other part of the program from touching that formatter while you are writing to it, which prevents memory corruption and data races. Finally, the function returns a fmt::Result. While JavaScript might allow a print command to fail silently, Rust requires a status report for every low level action. The Formatter does not build a giant string in the heap; instead, it performs String Streaming, pushing characters one by one to the destination. This is incredibly efficient because it uses almost zero extra RAM regardless of how large the message is. By returning a Result, the program knows immediately if the hardware successfully processed the output. This combination of zero cost abstractions and total memory control is why Rust can perform at the speed of C while remaining completely safe.
To view or add a comment, sign in
-
More from this author
-
📘 What I Learned About the Node.js fs Module (While Executing Code on the Server) Today, I spent time deeply understanding the Node.js fs (File Syst
Prince sah 3mo -
🚀 From Idea to Execution: Building an AI-Powered Code Editor (With a Real Compiler) Most code editors today help you write code. But what if your
Prince sah 3mo
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