Day 2/100 of JavaScript 🚀 Today’s Topic: "let", "const", "var", hoisting and TDZ. "var", "let", and "const" are used to declare variables, but they differ in scope and initialization behavior - "var" is function-scoped and during the creation phase it gets initialized with "undefined", so it can be accessed before assignment. - "let" and "const" are block-scoped and are registered in memory during creation, but not initialized immediately. This leads to TDZ (Temporal Dead Zone) a phase where the variable exists in memory but remains uninitialized and cannot be accessed. Accessing "let" or "const" variables before initialization results in a ReferenceError. - "const" must be initialized at declaration and cannot be reassigned. - "let" allows reassignment but not redeclaration in the same scope. These differences make "let" and "const" more predictable and safer compared to "var". #Day2 #JavaScript #100DaysOfCode
JavaScript Variables: Var, Let, Const, and TDZ Explained
More Relevant Posts
-
🚀 Why Does null Show as an Object in JavaScript? 🤯 While practicing JavaScript, I came across something interesting: let myVar = null; console.log(typeof myVar); // Output: object At first, it feels confusing… why is null an object? 🤔 💡 Here’s the simple explanation: null is actually a primitive value that represents "no value" or "empty". But when JavaScript was first created, there was a bug in the typeof operator. Due to this bug, typeof null returns "object" instead of "null". ⚠️ This behavior has been kept for backward compatibility, so changing it now would break existing code. 🔍 Key Takeaways: null → means "nothing" (intentional empty value) typeof null → returns "object" (this is a historical bug) Objects (like {}) also return "object" 💻 Example: let myObj = { name: "John" }; console.log(typeof null); // object ❌ (bug) console.log(typeof myObj); // object ✅ (correct) 📌 Conclusion: Even though both return "object", they are completely different in meaning. 👉 JavaScript is powerful, but it has some quirky behaviors—this is one of them! #JavaScript #WebDevelopment #CodingJourney #100DaysOfCode #FrontendDevelopment
To view or add a comment, sign in
-
-
🚀 Day 1/30 – JavaScript Challenge LeetCode 2667 – Create Hello World Function 🧩 Problem: Write a function that returns a new function. That new function should always return "Hello World", no matter what arguments are passed. 🧠 Explanation: createHelloWorld() returns another function. The returned function uses (...args) to accept any number of arguments. But we ignore all inputs and always return "Hello World". 💡 Key Concept: This problem is based on: Higher Order Functions (function returning function). Rest Parameters (...args). Function independence from input. #javascript #30Days #Leetcode
To view or add a comment, sign in
-
-
Day 4/100 of JavaScript 🚀 Today’s focus: Functions in JavaScript Functions are reusable blocks of code used to perform specific tasks Some important types with example code: 1. Parameterized function → takes input function greet(name) { return "Hello " + name; } greet("Apsar"); 2. Pure function → same input always gives same output, no side effects function add(a, b) { return a + b; } add(2, 3); 3. Callback function → function passed into another function function processUser(name, callback) { callback(name); } processUser("Apsar", function(name) { console.log("User:", name); }); 4.Function expression → function stored in a variable const multiply = function(a, b) { return a * b; }; 5.Arrow function → shorter syntax const square = (n) => n * n; Key understanding: Functions are first-class citizens in JavaScript — they can be passed, returned, and stored like values #Day4 #JavaScript #100DaysOfCode
To view or add a comment, sign in
-
Day 22/100 of JavaScript Today’s topic: Prototypes in JavaScript JavaScript uses a prototype-based inheritance model. Every object in JavaScript has an internal link to another object called its prototype. Example function Person(name) { this.name = name; } Person.prototype.greet = function () { console.log("Hello " + this.name); }; const user = new Person("Apsar"); user.greet(); Here, "greet" is not inside the object itself, but shared through the prototype. 🔹Prototype chain If a property or method is not found on the object, JavaScript looks up the prototype chain. console.log(user.toString()); 👉 "toString()" comes from the base object prototype. 🔑 Key points - Functions have a "prototype" property. - Objects inherit from their prototype. - Helps in memory efficiency by sharing methods. #Day22 #JavaScript #100DaysOfCode
To view or add a comment, sign in
-
Do you know how stacks work in JavaScript? Made a visual to understand LIFO, Big O trade-offs, and when stacks make sense — all in one diagram. #JavaScript #DataStructures #Algorithms #SoftwareEngineering
To view or add a comment, sign in
-
-
I've been writing JavaScript for over a year. Thought I understood var, let, and const. I didn't. "var a" inside a block accessible outside. Prints "10". "let b" inside the same block, try to access it outside and you get: ReferenceError: b is not defined Same block. Same code. Completely different behavior. Turns out var lives in global memory. let and const get their own separate block scope. Once the block is done, they're gone. This is why going back to fundamentals matters #JavaScript #WebDev #LearnInPublic #NamasteJavaScript
To view or add a comment, sign in
-
-
🚀 Day 4/30 – JavaScript Challenge Solved: Counter II (LeetCode 2665) Today’s problem was all about understanding closures and how functions can maintain their own state in JavaScript. What I learned: 1.How closures help preserve variable values across function calls 2.Creating multiple operations (increment, decrement, reset) using a single function 3.Clean use of arrow functions for concise code Approach: I created a function that stores the initial value and returns an object with three methods: 1.increment() -> increases value 2.decrement() -> decreases value 3.reset() -> resets to initial value All of this works because of closure, where the inner functions still remember the variable n. Key Insight: Closures are powerful when you need to encapsulate data and control how it’s modified — a very common pattern in real-world JavaScript applications. Consistency is the real game here 🔥 Let’s keep building, one day at a time. #Day4 #30DaysOfCode #JavaScript #WebDevelopment #CodingChallenge #LeetCode #Closures #LearningJourney
To view or add a comment, sign in
-
-
Already know how queues work? Made a visual to understand FIFO, Big O trade-offs, and when to use queues in JavaScript — all in one diagram. #JavaScript #DataStructures #Algorithms #SoftwareEngineering
To view or add a comment, sign in
-
-
JavaScript becomes a different language the moment you realize this: 👉 Functions are not just reusable blocks… they are values. And once you understand that, concepts like callbacks and higher-order functions stop feeling confusing and start feeling natural. In this video, I’ve broken it down step by step: How values behave in JavaScript How objects behave Why functions behave the same way (and why that matters) From there, everything builds logically: ✔ Passing functions as arguments ✔ Returning functions from functions ✔ What exactly a callback is ✔ What a higher-order function is ✔ How this leads to more flexible and reusable code No jargon. No unnecessary complexity. Just a clear, practical approach to a core JavaScript concept. 🎥 Watch here: https://lnkd.in/gM8ibZ6M This is Part 1 — next, we’ll explore how this shows up in real code with: setTimeout, forEach, map, filter #JavaScript #WebDevelopment #FrontendDevelopment #Programming #Coding #LearnToCode #JavaScriptDeveloper #SoftwareDevelopment #Developers #CodingJourney #TechEducation #Hosiyar #JS
Callback Functions and Higher Order Functions in JavaScript | JS Mastery #12
https://www.youtube.com/
To view or add a comment, sign in
-
Day 9/30 Functions, Parameters, and Return Values in JavaScript Functions in JavaScript are reusable blocks of code designed to perform specific tasks. They help improve organization, reduce repetition, and make programs easier to maintain. A function can receive Parameters, which act like placeholders for values that are passed in when the function is called. These parameters allow the function to work with dynamic input. After processing the input, a function can provide an output using the return statement. The returned value can then be stored, displayed, or used in further calculations. Together, functions, parameters, and return values make JavaScript logic flexible, reusable, and efficient. #M4ACELearningChallenge #QualityAssurance #AutomationTesting #JavaScript #LearningInPublic
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