Day 5 of JavaScript Mastery Journey

Table of contents
- Welcome to Day 5 of my JavaScript Mastery Journey! πβ¨
- Day 4: Recap πβ¨
- Day 5: Unraveling this, Prototypes, and Function Purity! π€―π
- 1. The Mysterious this Keyword: Who's Holding the Phone? ππ΅οΈββοΈ
- 2. Borrowing Powers: call(), apply(), and bind()! π¦ΈββοΈπ€
- 3. Sharing Skills: Prototypes and Inheritance! π€π§¬
- 4. Pure vs. Impure Functions: The Cleanliness Check! π§Όπ§Ή
- 5. Arrow Functions: The Speedy, Smart Function Shortcut! π―π£οΈ
- Summary

Welcome to Day 5 of my JavaScript Mastery Journey! πβ¨
Author: Ravindranath Porandla βοΈ
Day 4: Recap πβ¨
Today, we learned some incredibly powerful and fundamental JavaScript concepts that make our code smarter and more organized! Hereβs what we explored:
Higher-Order Functions (HOFs): We discovered functions that can take other functions as ingredients or even give them back as results! Think of them as our super flexible "Activity Helper" robots. π€π¦
Constructor Functions & the
new
Keyword: We learned how to create object "cookie cutters" with Constructor Functions and use thenew
keyword to stamp out many similar objects efficiently. πͺβοΈπFirst-Class Functions: We solidified the idea that functions in JavaScript are just like any other value β you can store them, pass them around, and even return them! They're like your favorite toy you can share! π§Έπ
IIFEs (Immediately Invoked Function Expressions): We mastered these special functions that run as soon as they're defined, creating private "treasure boxes" for our secret variables! π€«π§°
Prototypes & Prototypal Inheritance: We unlocked the secret world of how JavaScript objects quietly share abilities through a "shared schoolbag" (the prototype) and how objects can "inherit" skills from their "parent" objects! ππ¨βπ§βπ¦
Hello, future JavaScript wizard! π Welcome to Day 5 (or Day 6, let's call it Day 5 for now! π). Today, we're diving into some of the trickiest but most powerful parts of JavaScript: how the magical this
keyword works, how objects share their powers, and the difference between "clean" and "messy" functions! Get ready for some serious insights! πβ¨
Day 5: Unraveling this
, Prototypes, and Function Purity! π€―π
Today is all about understanding the hidden mechanics of JavaScript that make it so flexible and unique. We'll explore where this
points, how objects borrow abilities from each other, and what makes a function truly "pure." Let's jump in! π€ΈββοΈ
1. The Mysterious this
Keyword: Who's Holding the Phone? ππ΅οΈββοΈ
The this
keyword in JavaScript is a bit like a chameleon π¦βit changes its meaning depending on where and how a function is called. It almost always refers to an object, but which object changes!
Interview Definition:
this
refers to the object that is currently executing the code. Its value is dynamic, meaning it changes based on how the function containingthis
is invoked.Analogy: The Person Holding the Phone! π Imagine
this
is like "the hand holding the phone."If you call from your home π , your hand is holding the phone β
this
= your home object (or you!).If your friend calls from their office π’, their hand is holding the phone β
this
= your friend's office object (or your friend!).So,
this
always points to the "owner" or "context" of the function call!
How
this
Behaves in Different Places:Where
this
is UsedWhat
this
Refers ToAnalogy
Global Scope
The
window
object (in browsers) or global object (globalThis
orglobal
in Node.js).The "world" or "whole room" when no one specific is talking. π
Inside a Regular Function
The
window
object (in non-strict mode in browsers).A general announcement to the whole room. π£
Inside an Object Method
The object that owns/called the method.
The specific person who is talking from their own house. π
Inside an Arrow Function
It inherits
this
from its surrounding (parent) scope.A child copying exactly what their parent says. π§βπΌ
In Event Listeners
The element that triggered the event.
The specific button that was clicked! π±οΈ
With the
new
KeywordThe newly created object being built by the constructor.
The fresh cookie coming out of the cutter! πͺ
Export to Sheets
Examples to See
this
in Action:Global Scope (The Big Picture!):
console.log(this); // In a browser, this usually logs the 'window' object (the entire webpage). π
Inside a Regular Function (A General Announcement):
function showWhatAmI() { console.log(this); } showWhatAmI(); // In a browser (non-strict mode), this logs 'window' again. It's like a speaker announcing to everyone. π£οΈ
Inside an Object Method (The Owner Speaking!):
const robot = { name: "Unit-734", reportName: function () { // This is a METHOD of the 'robot' object console.log(`My name is ${this.name}.`); // 'this' here refers to the 'robot' object itself! } }; robot.reportName(); // Output: My name is Unit-734. β
Arrow Function (The Copycat!):
const game = { title: "Space Invaders", announceTitle: () => { // This is an ARROW function // Arrow functions don't have their own 'this'. // They 'inherit' 'this' from their surrounding code (which is the global scope here). console.log(`Now playing: ${this.title}`); } }; game.announceTitle(); // Output: Now playing: undefined (because 'this.title' refers to window.title, which is undefined) π€·ββοΈ
2. Borrowing Powers: call()
, apply()
, and bind()
! π¦ΈββοΈπ€
Sometimes, you want a function to use this
as if it belonged to a different object, even if it doesn't usually! This is like giving a superhero the power to temporarily use another hero's special gadget! π₯
2.1 call()
Method: "Use This Gadget, Right Now!" π
Interview Definition: The
call()
method allows you to immediately execute a function, explicitly setting whatthis
refers to inside that function. You pass individual arguments one by one.Analogy: Imagine you have a special "say hi" gadget. You give it to your friend Bob π§β𦱠and say, "Bob, use this gadget RIGHT NOW to say hello, and here's your age: 25." The gadget then "thinks" Bob is its owner.
Example:
function greet(age, city) { // Our general 'greet' function console.log(`Hi, I'm ${this.name} and I'm ${age} from ${city}.`); } const person = { name: "Ravi" }; // The object we want 'this' to refer to // Use 'call()' to make 'greet' act as if 'person' is its 'this' greet.call(person, 25, "Delhi"); // We call 'greet', set 'this' to 'person', and pass arguments individually. // Output: Hi, I'm Ravi and I'm 25 from Delhi. β
Inside
greet
,this
now points toperson
. Arguments (25
,"Delhi"
) are passed one by one.
2.2 apply()
Method: "Use This Toolbox, Right Now!" π§°π§
Interview Definition:
apply()
is almost identical tocall()
, but it takes the arguments as an array. It also executes the function immediately.Analogy: It's like giving your friend Bob the "say hi" gadget and saying, "Bob, use this gadget RIGHT NOW, and here's all your info in one toolbox (an array): [25, 'Delhi']."
Example:
function greet(age, city) { // Same 'greet' function console.log(`Hi, I'm ${this.name} and I'm ${age} from ${city}.`); } const person = { name: "Ravi" }; const personInfo = [25, "Hyderabad"]; // Arguments are in an array! // Use 'apply()' to make 'greet' act as if 'person' is its 'this' greet.apply(person, personInfo); // We call 'greet', set 'this' to 'person', and pass the array of arguments. // Output: Hi, I'm Ravi and I'm 25 from Hyderabad. β
2.3 bind()
Method: "Tie This Leash, Use Later!" πΆπ
Interview Definition:
bind()
does not execute the function immediately. Instead, it returns a brand-new function wherethis
is permanently fixed (bound) to a specified object. You can then run this new function whenever you want.Analogy: Imagine tying a dog leash πΆ. You tie the leash (use
bind()
) to your friend Bob (thethis
object) and your dog (the function). Now, wherever that dog goes, it's always tied to Bob. You don't walk the dog now, but you can save that "Bob-leashed-dog" and walk it whenever you're ready!Example:
function greet(age) { // Our 'greet' function console.log(`Hi, I'm ${this.name} and I'm ${age}.`); } const person = { name: "Ravi" }; // Use 'bind()' to create a NEW function where 'this' is always 'person' const greetRavi = greet.bind(person, 25); // 'greetRavi' is a NEW function! It doesn't run yet. console.log("Saving the function for later..."); greetRavi(); // Output: Hi, I'm Ravi and I'm 25. (Now it runs!) β
greetRavi
is a new function wherethis
is permanently locked toperson
.
3. Sharing Skills: Prototypes and Inheritance! π€π§¬
Remember our discussion about objects sharing abilities from Day 4? Now we'll go even deeper into the "Prototype Chain" β JavaScript's secret way for objects to borrow powers from each other!
3.1 What is a Prototype? The "Ask Your Teacher" Chain! π§βπ«β
Interview Definition: In JavaScript, every object (almost!) has a hidden internal property (often accessed as
__proto__
) that links it to another object called its prototype. This prototype object is like a blueprint or a shared toolbox that provides properties and methods that the first object can "inherit" or use.Analogy: The "Ask Your Teacher" Chain! π§βπ«π Imagine you're a student π§ and you're asked a question.
First, you check if you know the answer yourself (your own properties).
If not, you ask your teacher (your prototype!).
If the teacher doesn't know, they might ask the principal (the teacher's prototype!).
This "asking up the chain" continues until someone knows the answer, or you reach the top of the school (
null
), meaning no one knows.
Prototype Chain Visual:
Your Object β‘οΈ Its Prototype Object β‘οΈ Its Prototype's Prototype (like Object.prototype) β‘οΈ null (End of chain)
JavaScript keeps climbing this chain until it finds the method or property, or it gives up and returns
undefined
.Example:
const person = { // This is our 'teacher' object. greet: function () { console.log("Hello there!"); } }; // 'student' is created, and its prototype is set to 'person'. // So, 'student' can now 'ask' 'person' for help! const student = Object.create(person); // Object.create() is the best way to link prototypes safely! student.name = "Anya"; // 'student' has its own 'name' student.greet(); // Output: Hello there!
Even though
student
doesn't have agreet()
method directly, JavaScript looks up its prototype chain, findsgreet()
onperson
, and uses it! β¨
3.2 What is Prototypal Inheritance? Borrowing Without Copying! π€π
Interview Definition: Prototypal inheritance is the fundamental way objects in JavaScript can inherit (access and use) properties and methods from other objects by linking to them via their prototype chain.
Analogy: Borrowing Skills from an Elder Sibling! π§βπ€βπ§ Instead of copying all your elder sibling's cool toys or skills, you just know that if you don't have something, you can ask your sibling to borrow it or do it for you! That's inheritance without duplication. You share the skill, not copy it!
Example:
const animal = { // Our 'parent' animal blueprint with shared abilities sound: "Generic sound", makeSound: function () { console.log(this.sound); // 'this' will refer to the animal *calling* makeSound } }; // 'dog' is created, and its prototype is set to 'animal' const dog = Object.create(animal); dog.sound = "Woof!"; // 'dog' has its own 'sound' property dog.makeSound(); // Output: Woof! (Even though makeSound is on 'animal', 'this.sound' uses 'dog's sound!)
dog
didn't definemakeSound()
, so it inherited it fromanimal
. But becausethis
insidemakeSound
refers to thedog
object whendog.makeSound()
is called, it correctly usesdog.sound
. Clever, right? π§
3.3 Why You Should NOT Use __proto__
! π¨π«
You might sometimes see __proto__
(with two underscores!) used to access or set an object's prototype. Avoid using it directly in your code!
Why to Avoid:
Deprecated: It's an old, unofficial way. Think of it like using an ancient, rickety bridge instead of a modern, safe one. π
Not Standard/Safe: While it often works, it's not officially part of the language specification in the same way
Object.create()
is.Performance: Using it can sometimes be slower.
Confusing: Can lead to hard-to-find bugs if not used carefully.
Example (DO NOT DO THIS!):
const dog = {}; dog.__proto__ = animal; // β Avoid using __proto__ directly like this!
3.4 Why Use Object.create()
Instead! β
π
Benefit:
Object.create()
is the modern, safe, and official way to create a new object and explicitly set its prototype.Example:
const parentObject = { greet: function () { console.log("Hello!"); } }; const childObject = Object.create(parentObject); // β This is the correct, safe way! childObject.name = "Max"; childObject.greet(); // Output: Hello!
3.5 Prototype vs. .prototype
vs. __proto__
! π€― (A quick clarification)
This can be confusing, but here's a simple way to remember:
Term | What it Is / When to Use | Analogy |
__proto__ | The actual, internal link from an object instance to its prototype object. (Avoid using directly!) | The secret invisible string connecting your object to its shared toolbag. π» |
.prototype | A property that exists only on constructor functions (and Classes). It's the object that will become the __proto__ for objects created by that constructor. | The blueprint attached to the cookie cutter itself, saying "all cookies made by me will have these shared ingredients!" π |
Object.create(obj) | A method to safely create a new object and set obj as its __proto__ (prototype). | The proper way to make a new cookie and tell it "your shared blueprint is this one!" β |
Export to Sheets
Constructor + Prototype Example:
function Person(name) { // This is our CONSTRUCTOR FUNCTION this.name = name; } // We add a method to the Person CONSTRUCTOR'S .prototype property Person.prototype.sayHi = function () { // All 'Person' objects will share THIS 'sayHi' function! console.log(`Hi, I'm ${this.name}!`); }; const p1 = new Person("Luna"); // Create a new Person object const p2 = new Person("Leo"); // Create another new Person object p1.sayHi(); // Output: Hi, I'm Luna! p2.sayHi(); // Output: Hi, I'm Leo!
Both
p1
andp2
share the same single copy of thesayHi()
method viaPerson.prototype
. This saves memory! πΎ
π― When to Use Prototypes:
Many Similar Objects: When you need a way for many objects of the same "type" to share common behaviors (like all
Person
objects having asayHi
method).Memory Optimization: To avoid creating separate copies of the same method for every single object, which saves computer memory. π§
Inheritance: As the core way to build inheritance relationships where one object can extend or borrow from another. π§¬
4. Pure vs. Impure Functions: The Cleanliness Check! π§Όπ§Ή
In programming, functions can be like neat chefs or messy chefs! Understanding the difference helps you write better, more predictable code.
4.1 What's the Difference?
Interview Definition:
Pure Function: A function that always gives the exact same output for the exact same input and does not cause any changes outside itself (no "side effects"). It's reliable and predictable! β
Impure Function: A function that might produce different output for the same input, or it changes something outside its own world (it has "side effects"). It's less predictable! β
Analogy: The Juice Machine! π§ Imagine you're a juice machine!
Pure Function: Every time you put in 2 apples ππ, you always get the same amount of apple juice. You don't spill juice on the table, and you don't keep a count of how much juice you've made. Clean and consistent!
Impure Function: You put in 2 apples, but sometimes you give more juice, sometimes less. Or, you might spill some juice on the table, or keep a running tally on a whiteboard next to the machine. You're changing things outside just making juice! π¦
4.2 Pure Function: Predictable & Clean! β π―
Rules:
Same input β Same output: If you call it with
(5, 3)
, it will always return8
.No side effects: It doesn't change any global variables, modify the webpage, save to a database, or make network calls. It only does its job and gives back a result.
Simple Example:
function add(a, b) { // This function only uses its inputs 'a' and 'b' return a + b; // It only gives back a result, doesn't change anything else. } console.log(add(2, 3)); // Always 5 console.log(add(2, 3)); // Still 5! Predictable! β
Another Pure Example:
function multiplyByTwo(number) { // Takes a number, gives back a multiplied number return number * 2; } console.log(multiplyByTwo(4)); // Always 8
This function is a good citizen! It does its job cleanly. π§βπ¬
4.3 Impure Function: Unpredictable & Messy! βποΈ
Characteristics:
Might return different values even with the same inputs (e.g., if it uses the current time or a random number).
Changes something outside itself (e.g., modifies a global variable, changes content on a webpage, makes a network request). These are called "side effects."
Example 1: Changing a Global Variable (Messy!)
let totalScore = 0; // This is a global variable (outside the function) function addPoints(points) { totalScore = totalScore + points; // β οΈ This function CHANGES 'totalScore' outside itself! return totalScore; } console.log(addPoints(10)); // Output: 10 console.log(addPoints(10)); // Output: 20 (Same input, different output due to global change!) β
Example 2: Using Current Time (Unpredictable!)
function giveCurrentTime() { return new Date().toLocaleTimeString(); // β οΈ This uses the current time, which is always changing! } console.log(giveCurrentTime()); // Output: e.g., "3:30:00 PM" // Wait a second... console.log(giveCurrentTime()); // Output: e.g., "3:30:01 PM" (Different output for the "same" input - none!) β
4.4 Why Do We Care About Pure Functions? π
Predictability: Pure functions are easier to understand because you know exactly what they'll do every time.
Easier Testing: You can test them easily! Just give them an input and check the output. No need to worry about setting up complex scenarios. π§ͺ
No Unexpected Bugs: They don't accidentally mess up other parts of your code because they don't change anything outside themselves. π
Better Reusability: Because they're self-contained, you can use them anywhere without fear of side effects. β»οΈ
π Tips to Remember for Pure Functions:
Focus on Inputs & Outputs: Think of them like a mathematical function:
f(x) = y
.Avoid "Outside" Changes: Don't modify global variables, change the webpage (DOM), save data, or make network requests inside a pure function.
Use
const
&return
: Favorconst
for variables inside, and alwaysreturn
a value.Beware of Randomness/Time: Functions using
Math.random()
ornew Date()
are usually impure because their output isn't solely based on their direct inputs.
5. Arrow Functions: The Speedy, Smart Function Shortcut! π―π£οΈ
Imagine you usually write a full sentence to tell someone to do something. Arrow functions are like a way to say the same thing using just a few simple words and a cool arrow symbol! They were added to JavaScript to make writing functions quicker and sometimes clearer.
What are they? Arrow functions are a newer, shorter way to write functions. They look a bit different from the
function
keyword we've seen before.Why use them? They can make your code look cleaner and sometimes behave in a super helpful way, especially with the
this
keyword (which we explored on Day 5!).
5.1 Basic Syntax: Less Typing, More Fun! βοΈβ¨
Let's see how they look compared to regular functions. The main magic is the =>
(the "arrow")!
No
function
keyword: You don't need to typefunction
anymore!The Arrow (
=>
): This arrow goes between the function's inputs (parameters) and its instructions (body).Inputs in Parentheses
()
: Just like regular functions, you list your inputs inside parentheses. If you have only one input, you can even skip the parentheses!One-Line Wonder (Implicit Return): If your function's job is just one line of code that calculates something, you can skip the curly braces
{}
AND thereturn
keyword! JavaScript will automatically return the result of that single line.
Simple Examples to See the Difference!
Example 1: Adding Two Numbers β
Regular Function:
JavaScript
function addNormal(num1, num2) { return num1 + num2; } console.log("Normal add:", addNormal(2, 3)); // Output: Normal add: 5
Arrow Function (The Shortcut!):
JavaScript
const addArrow = (num1, num2) => num1 + num2; // No 'function', no '{}', no 'return'! console.log("Arrow add:", addArrow(2, 3)); // Output: Arrow add: 5
See how much shorter that is? Super neat! β¨
Example 2: Saying Hello (One Input) π
Regular Function:
JavaScript
function sayHelloNormal(name) { console.log("Hello, " + name + "!"); } sayHelloNormal("Anna"); // Output: Hello, Anna!
Arrow Function (Even Shorter for One Input!):
JavaScript
const sayHelloArrow = name => console.log(`Hello, ${name}!`); // One input, so no () needed around 'name'! sayHelloArrow("Bob"); // Output: Hello, Bob!
(Remember those cool backticks
`
for easy sentences with variables, called template literals! π¬)
Example 3: Doing More Than One Thing (Multiple Lines) π¦ If your function needs to do a few things, you'll still need curly braces {}
and the return
keyword (if you want to give back a result).
const calculateAndDisplay = (itemPrice, quantity) => {
const totalCost = itemPrice * quantity; // First step
console.log(`You bought ${quantity} items.`); // Second step
return `Your total is $${totalCost}.`; // Third step, returning a message
};
console.log(calculateAndDisplay(5, 4));
// Output:
// You bought 4 items.
// Your total is $20.
5.2 The BIG Difference: How this
Works! (The Copycat this
) ππ
This is the most important thing to remember about arrow functions, and it's a common π Interview Question! π
Interview Question: "What is the main difference between arrow functions and regular functions regarding the
this
keyword?"- Answer: "Arrow functions do not have their own
this
context. Instead, they lexically bindthis
. This means they simply inherit thethis
value from the code that surrounds them (their 'parent scope') at the time they are created. Regular functions, on the other hand, determine theirthis
value dynamically based on how or where they are called."
- Answer: "Arrow functions do not have their own
Analogy: The
this
Copycat! π Remember from Day 5 thatthis
is like "who is holding the phone" π.A regular function is like a person who always grabs their own phone and figures out who
this
is based on how they are calling.An Arrow Function is like a curious copycat monkey! π It doesn't have its own phone. Instead, it looks at whoever its parent (the code around it) is, and just copies their
this
! It doesn't care how it is called later; it just remembers whatthis
was when it was born.
Example: this
in Action (Regular vs. Arrow in an Object) Let's make a robot that can say its name!
const robot = {
name: "Robo-Pals",
batteryLevel: 90,
// π€ Regular function method: 'this' will point to the 'robot' object
reportStatusRegular: function() {
console.log(`Regular: My name is ${this.name} and my battery is ${this.batteryLevel}%.`);
},
// π€ Arrow function method: 'this' will NOT point to the 'robot' object.
// It will inherit 'this' from its surrounding (global) scope, which is 'window' in a browser.
reportStatusArrow: () => {
// In a browser, this.name would be window.name (which is usually empty)
// and this.batteryLevel would be window.batteryLevel (also undefined).
console.log(`Arrow: My name is ${this.name} and my battery is ${this.batteryLevel}%.`);
}
};
robot.reportStatusRegular(); // Output: Regular: My name is Robo-Pals and my battery is 90%. (Correct! β
)
robot.reportStatusArrow(); // Output: Arrow: My name is undefined and my battery is undefined%. (Oh no! β)
See how the arrow function here didn't work as expected inside the object method? That's because it copied this
from the "outside world" (the global window
object), not from robot
.
Example: Where Arrow Functions Shine (Callbacks!) β¨ Arrow functions are fantastic when you want a nested function (like a setTimeout
callback) to keep the this
context of its parent.
const gamePlayer = {
playerName: "GamerKid",
score: 0,
// This is a REGULAR function method for 'gamePlayer'
startBoosting: function() {
console.log(`${this.playerName} is starting boost! π`); // 'this' here is 'gamePlayer'
// Now, let's use an ARROW function for the setTimeout callback
// The arrow function COPIES 'this' from its parent 'startBoosting' function!
setTimeout(() => {
this.score += 10; // This 'this' correctly refers to 'gamePlayer'! β
console.log(`${this.playerName} got a boost! Score: ${this.score}`);
}, 1000); // Wait 1 second
}
};
gamePlayer.startBoosting();
// Output:
// GamerKid is starting boost! π
// (after 1 second)
// GamerKid got a boost! Score: 10
This is why arrow functions are so often used for callbacks inside methods! They help you avoid tricky this
problems. π§
5.3 Other Small Differences (Just for Your Info!):
No
arguments
Object: Regular functions automatically get a special invisible "bag" calledarguments
that holds all the inputs they were given. Arrow functions don't get this automatic bag. If you need to gather all inputs, you'd use something called...rest
parameters ((...args) => { ... }
). ποΈNot for Building New Objects: You cannot use an arrow function with the
new
keyword (like our cookie cutters πͺ) to create new objects. They aren't designed to be "constructor functions."
5.4 When to Use Arrow Functions & When to Be Careful! π€π‘
β Use Arrow Functions When:
You need a short, simple function for a quick task.
You want
this
to automatically be inherited from the surrounding code (especially common in callbacks forsetTimeout
,forEach
, Promises'.then()
, etc.). They help avoidthis
confusion!
β Be Careful (or Avoid) Arrow Functions When:
You are defining a method directly on an object and you need
this
to refer to that specific object. (Use a regularfunction
for methods instead!)You need to use the
new
keyword to create instances (they can't be constructors).
That's a lot of super important concepts for Day 5! You've tackled some of the trickiest parts of JavaScript today. Keep up the amazing work! πͺπ
Summary
Day 5: Today's Learnings Are... πβ¨
Today, we untangled some of JavaScript's most powerful and sometimes trickiest concepts! Hereβs a quick recap of our adventures:
The Mysterious
this
Keyword: We discovered howthis
is like a chameleon, changing who it points to based on how and where a function is called β whether it's the global window π, an object π , or inherited from a parent in arrow functions β‘οΈ.Borrowing Powers (
call()
,apply()
,bind()
): We learned how to make functions temporarily "borrow" another object's identity!call()
andapply()
execute immediately (with arguments passed individually or in an array π₯), whilebind()
returns a new function withthis
permanently fixed for later use πΆπ.Prototypes & Prototypal Inheritance: We unlocked the secret of how objects share abilities through a "prototype chain," like a student asking their teacher for answers π§βπ«. We saw how objects can "inherit" skills from others without copying them, saving memory! π‘π
Pure vs. Impure Functions: We explored the difference between "clean" functions that always give the same output for the same input and don't cause side effects (like a predictable juice machine! π§β ) and "messy" ones that can change things outside themselves ποΈβ.
Arrow Functions: Our new favorite shortcut for writing functions! π―π£οΈ We learned their concise syntax, but most importantly, how they handle
this
like a copycat π, inheriting it from their surroundings β which is super handy for callbacks! β¨
What a day of deep dives! You're really mastering the heart of JavaScript now. πͺπ§
Follow more at: Ravindranath Porandla Blog π§ π
β Ravindranath Porandla π§βπ»
Subscribe to my newsletter
Read articles from Ravindranath Porandla directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
