<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/my-odin-project-journey-day-8-factory-functions-closures-and-private-data-lbrnsybhl" -->

---
title: My Odin Project Journey — Day 8: Factory Functions,...
description: A personal learning log from a self-taught developer working through The Odin Project curriculum, covering JavaScript variable scope (let/const vs var),...
canonical: https://daily.dev/posts/my-odin-project-journey-day-8-factory-functions-closures-and-private-data-lbrnsybhl
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: My Odin Project Journey — Day 8: Factory Functions, Closures, and Private Data | daily.dev
og:description: A personal learning log from a self-taught developer working through The Odin Project curriculum, covering JavaScript variable scope (let/const vs var),...
og:url: https://daily.dev/posts/my-odin-project-journey-day-8-factory-functions-closures-and-private-data-lbrnsybhl
og:image: https://api.daily.dev/og/posts/LbrnsYbHl.png
og:image:alt: My Odin Project Journey — Day 8: Factory Functions, Closures, and Private Data
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# My Odin Project Journey — Day 8: Factory Functions, Closures, and Private Data

**[Medium](https://daily.dev/sources/medium_js)** · 7 min read · 8 upvotes · 1 comments

## Summary

A personal learning log from a self-taught developer working through The Odin Project curriculum, covering JavaScript variable scope (let/const vs var), closures, factory functions versus constructors, using closures to simulate private data, object composition as an alternative to prototypal inheritance, and a first encounter with IIFEs. The author walks through code examples for each concept and candidly notes which parts they still don't fully grasp, especially composition versus inheritance and the practical use case for IIFEs.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://abdullahoyediran.medium.com/my-odin-project-journey-day-8-factory-functions-closures-and-private-data-24c2048aad1e>

## Questions this post answers

### How do you create private variables in JavaScript using factory functions instead of classes?

Private variables are created by declaring them inside a factory function and returning only functions that close over them, never the variable itself. For example, a createUser function can declare 'let reputation = 0' internally, then return getReputation and giveReputation functions that read and modify it via closure, while the returned object has no direct reputation property outside code can overwrite.

_Developers weighing encapsulation patterns in JavaScript can find more closure-based examples curated on daily.dev._

### What is the difference between a factory function and a constructor function in JavaScript?

A constructor is invoked with 'new', can use 'this', and naturally supports prototypal inheritance, while a factory function is just a regular function that returns an object directly without 'new' and without prototype-based method sharing. Both can create objects with similar shapes, but constructors share methods via the prototype chain whereas factory functions recreate new function instances per call.

_Those deciding between object-creation patterns in JavaScript can track deeper comparisons on daily.dev._

## Community discussion

Top comments from developers on daily.dev.

**@nikhil3** · 0 upvotes

> I had the same feeling when I first learned about IIFEs like, where am I ever going to use this? If I need to create a function that’s immediately called, why not just call it right after declaring it?
>
> Now I’ve actually started using IIFEs quite often for scripts, migration pipelines, and server startup code. An async IIFE is especially useful because it lets me use "await" directly without having to wrap the code in another named async function, and since it’s invoked immediately, the initialization code runs as soon as the script is evaluated.

## Similar posts on daily.dev

- [JavaScript Daily \#1: Closures Aren’t About Remembering Values](https://daily.dev/posts/javascript-daily-1-closures-aren-t-about-remembering-values-qlhawft1d) · Medium · 0 upvotes · 0 comments
- [JavaScript Interview Preparation Challenge : Day 3](https://daily.dev/posts/javascript-interview-preparation-challenge-day-3-dqg1oqb41) · Medium · 1 upvotes · 0 comments
- [The Odin Project: Why It’s One of the Best Ways to Learn Web Development](https://daily.dev/posts/the-odin-project-why-it-s-one-of-the-best-ways-to-learn-web-development-pe8mfjemv) · Ruby Flow · 4 upvotes · 0 comments

---

Tags: [#javascript](https://daily.dev/tags/javascript)

[View this post on daily.dev](https://daily.dev/posts/my-odin-project-journey-day-8-factory-functions-closures-and-private-data-lbrnsybhl)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"My Odin Project Journey — Day 8: Factory Functions, Closures, and Private Data","url":"https://daily.dev/posts/my-odin-project-journey-day-8-factory-functions-closures-and-private-data-lbrnsybhl","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/my-odin-project-journey-day-8-factory-functions-closures-and-private-data-lbrnsybhl"},"datePublished":"2026-10-07T10:46:54.869Z","dateModified":"2026-10-07T10:51:02.595Z","description":"A personal learning log from a self-taught developer working through The Odin Project curriculum, covering JavaScript variable scope (let/const vs var),...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/adc3edf9c27ee13b1e1b14ffdb086d40?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/adc3edf9c27ee13b1e1b14ffdb086d40?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Medium","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Medium","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/medium","url":"https://daily.dev/sources/medium_js"},"commentCount":1,"discussionUrl":"https://daily.dev/posts/my-odin-project-journey-day-8-factory-functions-closures-and-private-data-lbrnsybhl","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":8},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":1}],"keywords":"javascript","timeRequired":"PT7M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Medium","item":"https://daily.dev/sources/medium_js"},{"@type":"ListItem","position":3,"name":"My Odin Project Journey — Day 8: Factory Functions, Closures, and Private Data"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/my-odin-project-journey-day-8-factory-functions-closures-and-private-data-lbrnsybhl","comment":[{"@type":"Comment","text":"I had the same feeling when I first learned about IIFEs like, where am I ever going to use this? If I need to create a function that’s immediately called, why not just call it right after declaring it?\nNow I’ve actually started using IIFEs quite often for scripts, migration pipelines, and server startup code. An async IIFE is especially useful because it lets me use “await” directly without having to wrap the code in another named async function, and since it’s invoked immediately, the initialization code runs as soon as the script is evaluated.","datePublished":"2026-10-08T04:18:11.342Z","url":"https://daily.dev/posts/LbrnsYbHl#c-22s4Xd4o0","author":{"@type":"Person","name":"Nikhil","url":"https://daily.dev/nikhil3","image":"https://avatars.githubusercontent.com/u/123929646?v=4"}}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/my-odin-project-journey-day-8-factory-functions-closures-and-private-data-lbrnsybhl#faq","mainEntity":[{"@type":"Question","name":"How do you create private variables in JavaScript using factory functions instead of classes?","acceptedAnswer":{"@type":"Answer","text":"Private variables are created by declaring them inside a factory function and returning only functions that close over them, never the variable itself. For example, a createUser function can declare 'let reputation = 0' internally, then return getReputation and giveReputation functions that read and modify it via closure, while the returned object has no direct reputation property outside code can overwrite. Developers weighing encapsulation patterns in JavaScript can find more closure-based examples curated on daily.dev."}},{"@type":"Question","name":"What is the difference between a factory function and a constructor function in JavaScript?","acceptedAnswer":{"@type":"Answer","text":"A constructor is invoked with 'new', can use 'this', and naturally supports prototypal inheritance, while a factory function is just a regular function that returns an object directly without 'new' and without prototype-based method sharing. Both can create objects with similar shapes, but constructors share methods via the prototype chain whereas factory functions recreate new function instances per call. Those deciding between object-creation patterns in JavaScript can track deeper comparisons on daily.dev."}}]}
```

