This repository demonstrates core JavaScript concepts with practical examples:
-
Lexical Scope & Closure
- Functions can access variables from their parent scope.
- Closures allow a function to "remember" these variables even after the parent scope is gone.
-
IIFE (Immediately Invoked Function Expression)
- Functions that run immediately after being defined.
- Useful for creating private variables and avoiding global scope pollution.
-
Closure with Parameters
- Demonstrates how closures can manage dynamic values (like credits, counters, API limits).
- Useful for state management and resource control.
-
Prototype Inheritance (
prototype-inheritance.js
)- Demonstrates how objects can inherit properties and methods from other objects using
Object.setPrototypeOf
. - Explains the differences between
__proto__
and modern methods likegetPrototypeOf
andsetPrototypeOf
. - Shows how multiple objects can form a prototype chain.
- Demonstrates how objects can inherit properties and methods from other objects using
-
Getters & Setters (
getters-setters.js
)- Shows how to use
get
andset
for encapsulating object properties. - Demonstrates property overriding and prototype chain behavior.
- Compares
Object.keys()
vsfor...in
when iterating over properties.
- Shows how to use
-
Object Constructors (
object-constructors.js
)- Uses constructor functions to create reusable object blueprints.
- Adds shared methods via
prototype
to optimize memory usage. - Explains how instances access properties/methods through the prototype chain.
-
ES6 Classes & Inheritance (
classes-inheritance.js
)- Demonstrates modern class-based syntax for inheritance.
- Uses
extends
andsuper()
to inherit properties and methods. - Compares class inheritance with traditional prototype-based inheritance.