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
JavaScript Functions: Day 4 of 100 Days of Code
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 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
-
Day 7/100 of JavaScript 🚀 Today’s Topic: Taking input in JavaScript. In browser-based JavaScript, input can be taken using: - "prompt()" - Input fields (DOM) On platforms like LeetCode, input is already provided as function parameters Example: var twoSum = function(nums, target) { // input is already given }; So the focus is on writing logic, not handling input However, some coding platforms (or local environments) do not provide inbuilt input handling. In such cases, we use Node.js Example: process.stdin.on("data", (data) => { const input = data.toString().trim(); console.log(input); }); This allows us to read input from the console Key understanding: - Platforms like LeetCode handle input internally - Other platforms and local setups require manual input handling using Node.js Understanding both approaches is important for coding practice #Day7 #JavaScript #100DaysOfCode
To view or add a comment, sign in
-
🚀Day 30 — Scope Chain & Scope Types in JavaScript (Simplified) Understanding scope is one of the most important fundamentals in JavaScript 🚀 --- 🔍 What is Scope? 👉 Scope decides where variables can be accessed in your code In simple words: 👉 “Who can access what?” --- ⚡ Types of Scope 1. Global Scope 👉 Variables declared outside functions or blocks let name = "John"; function greet() { console.log(name); // accessible } --- 2. Function Scope 👉 Variables declared inside a function function test() { let age = 25; console.log(age); } console.log(age); // ❌ Error --- 3. Block Scope 👉 Variables declared with let and const inside {} if (true) { let city = "Delhi"; } console.log(city); // ❌ Error --- 🔗 What is Scope Chain? 👉 If JS can’t find a variable in current scope, it looks in the outer scope, then outer again… until global scope. This is called the Scope Chain --- 🚀 Why it matters ✔ Prevents variable conflicts ✔ Helps understand closures ✔ Improves debugging skills --- 💡 One-line takeaway: 👉 “JavaScript looks upward to find variables — that’s the scope chain.” --- Mastering scope makes closures, hoisting, and debugging much easier. #JavaScript #Scope #ScopeChain #WebDevelopment #Frontend #100DaysOfCode 🚀
To view or add a comment, sign in
-
🧠 Day 13 — Class vs Prototype in JavaScript (Simplified) JavaScript has both Classes and Prototypes — but are they different? 🤔 --- 🔍 The Truth 👉 JavaScript is prototype-based 👉 class is just syntactic sugar over prototypes --- 📌 Using Class (Modern JS) class Person { constructor(name) { this.name = name; } greet() { console.log(`Hello ${this.name}`); } } const user = new Person("John"); user.greet(); // Hello John --- 📌 Using Prototype (Core JS) function Person(name) { this.name = name; } Person.prototype.greet = function () { console.log(`Hello ${this.name}`); }; const user = new Person("John"); user.greet(); // Hello John --- 🧠 What’s happening? 👉 Both approaches: Create objects Share methods via prototype Work almost the same under the hood --- ⚖️ Key Difference ✔ Class → Cleaner, easier syntax ✔ Prototype → Core JavaScript mechanism --- 🚀 Why it matters ✔ Helps you understand how JS works internally ✔ Useful in interviews ✔ Makes debugging easier --- 💡 One-line takeaway: 👉 “Classes are just a cleaner way to work with prototypes.” --- #JavaScript #Prototypes #Classes #WebDevelopment #Frontend #100DaysOfCode
To view or add a comment, sign in
-
🧠 JavaScript Hoisting Explained Simply Hoisting is one of those JavaScript concepts that can feel confusing — especially when your code behaves unexpectedly. Here’s a simple way to understand it 👇 🔹 What is Hoisting? Hoisting means JavaScript moves declarations to the top of their scope before execution. But there’s a catch 👇 🔹 Example with var console.log(a); var a = 10; Output: undefined Why? Because JavaScript internally treats it like: var a; console.log(a); a = 10; 🔹 What about let and const? console.log(b); let b = 20; This throws a ReferenceError. Because "let" and "const" are hoisted too — but they stay in a “temporal dead zone” until initialized. 🔹 Function hoisting Functions are fully hoisted: sayHello(); function sayHello() { console.log("Hello"); } This works because the function is available before execution. 🔹 Key takeaway • "var" → hoisted with "undefined" • "let/const" → hoisted but not initialized • functions → fully hoisted 💡 One thing I’ve learned: Many “weird” JavaScript bugs come from not understanding hoisting properly. Curious to hear from other developers 👇 Did hoisting ever confuse you when you started learning JavaScript? #javascript #frontenddevelopment #webdevelopment #reactjs #softwareengineering #developers
To view or add a comment, sign in
-
-
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
To view or add a comment, sign in
-
🍃 Gist of some minutes of the day - 9th April 2026 ❓ What happens behind simple JavaScript code? Since I got into the basics of JavaScript—scope and variables—I have noticed one thing. Maybe it's late to notice, yet I’m interested in going deeper. It's just that in any JavaScript program, if you get an error in the middle or at any other line, the remaining lines of code won't get executed. ❓ Why won't it get executed if an error occurs? It's because JavaScript follows a single-threaded execution model. ❓ Then, I got another question, What if JavaScript needs to handle many more tasks? Yes! It can, by using: ---> Call Stack + Web APIs + Callback Queue + Event Loop ❓ Next, I raised another question - What do all these do and how? Simply, when there is a task that takes time to execute and makes other tasks wait, JavaScript uses Web APIs. These Web APIs make the task wait by using an OS timer or other mechanisms, allowing other tasks to execute. Once the timer finishes, JavaScript moves the function to the Callback Queue. If there exists a function or task, then it executes it. Here, the Web API won't hold a single line of code that has to wait. It holds the task. A simple example is given in the image. That’s a simple code snippet to understand what happens and how JavaScript can handle multiple things. It can be applied to concepts such as fetching APIs or other browser-related tasks. ⏳ Behind the scenes: ▪️ It sends the task to the Web API to hold it ▪️ JavaScript becomes free ▪️ Then it executes the next tasks ▪️ Once completed, it goes to the Callback Queue ▪️ It checks if there is a function to be executed ▪️ Then executes it if it exists I still have more questions, and I would like to receive more questions from anyone interested in diving deeper. It may seem easy, but the concept behind it is deep and interesting. Meet you all later with explorable info, With Universe, Swetha. #JavaScript #SelfLearn #Basics #FoundationalValue
To view or add a comment, sign in
-
-
Ever wondered what actually happens when you use new in JavaScript? 🤔 Today I learned: 👉 How objects are created behind the scenes 👉 How prototypes are linked 👉 How constructors build instances Documented everything in this article 👇 https://lnkd.in/gr2UykHg #JavaScript #100DaysOfCode #WebDev #chaicode Chai Code Hitesh ChoudharyPiyush Garg Akash Kadlag Suraj Kumar Jha
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