6 Challenges, 1 Goal: Mastering JavaScript Logic 🚀 I’m pushing my boundaries today by knocking out 6 different coding challenges in a single session. From basic arithmetic to matrix manipulation, here’s a look at what I covered for Day 02: The Highlights: BigInt Power: Tackled "A Very Big Sum" by using BigInt to handle integers that exceed the standard 64-bit float limit. Matrix Logic: Solved "Diagonal Difference" by calculating the absolute variance between primary and secondary diagonals in a 2D array. String Formatting: Built a right-aligned "Staircase" using .repeat()—a great exercise for visualizing loops. The Code Breakdown: 1. Handling Large Sums (The BigInt Way) const arr = [1000000001, 1000000002, 1000000003, 1000000004, 1000000005] function veryBigSum(arr) { let result = 0n; for(let i = 0; i<arr.length;i++) { result += BigInt(arr[i]) } return result; } console.log(veryBigSum(arr)) } 2. 2D Array Diagonal Difference const arr = [ [1, 2, 3], [4, 5, 6], [9, 8, 9] ] function diagonalDifference(arr) { let primarySum = 0; let secondarySum = 0; let n = arr.length; for(let i =0; i<n; i++) { primarySum +=arr[i][i]; secondarySum +=arr[i][n-1-i] } return Math.abs(primarySum - secondarySum) } console.log(diagonalDifference(arr)) 3. Right-Aligned Staircase const n = 6; function staircase(n) { for(let i =1; i<=n; i++) { let spaces = ' '.repeat(n-i) let hashes = '#'.repeat(i) console.log(spaces + hashes) } } staircase(n) Building consistency is key, but today was all about momentum. Each problem solved is a tool added to the kit. 🛠️ #JavaScript #WebDevelopment #CodingChallenge #100DaysOfCode #ProblemSolving #SoftwareEngineering
Mastering JavaScript Logic with BigInt and Matrix Challenges
More Relevant Posts
-
🚀 JavaScript Simplified Series — Day 25 Imagine this 👇 You have a list of 100 items… And you want to add a click event on each item 😵 Will you do this? let items = document.querySelectorAll("li") items.forEach(item => { item.addEventListener("click", function() { console.log("Item clicked") }) }) Works… but not efficient ❌ 👉 What if new items are added later? 👉 You’ll have to add event again 😩 🔥 Solution → Event Delegation 🔹 Idea Instead of adding event to every child… 👉 Add event to parent And detect which child was clicked 🔹 Example <ul id="list"> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> </ul> let list = document.querySelector("#list") list.addEventListener("click", function(e) { console.log(e.target.innerText) }) 👉 Click any item → it works 😎 🔍 How it works? Because of event bubbling 👉 Event child se parent tak travel karta hai Parent catches it 🔹 Why Event Delegation is Powerful? ✅ Less code ✅ Better performance ✅ Works for dynamic elements 🔥 Real Life Example Think of a classroom 🎓 Instead of asking each student individually… 👉 Teacher asks whole class Jo respond kare → identify karo 🔥 Simple Summary Event Delegation → parent handles child events Uses → event bubbling Benefit → efficient & scalable 💡 Programming Rule Don’t attach events everywhere. Use delegation smartly. If you want to learn JavaScript in a simple and practical way, you can follow these YouTube channels: • Rohit Negi • Hitesh Choudhary (Chai aur Code) 📌 Series Progress Day 1 → What is JavaScript Day 2 → Variables & Data Types Day 3 → Type Conversion & Operators Day 4 → Truthy & Falsy + Comparison Operators Day 5 → If Else + Switch + Ternary Day 6 → Loops Day 7 → Break + Continue + Nested Loops Day 8 → Functions Basics Day 9 → Arrow + Default + Rest Parameters Day 10 → Callback & Higher Order Functions Day 11 → Arrays Basics Day 12 → Array Methods Day 13 → Array Iteration Day 14 → Advanced Array Methods Day 15 → Objects Basics Day 16 → Object Methods + this Day 17 → Object Destructuring Day 18 → Spread & Rest Day 19 → Advanced Objects Day 20 → DOM Introduction Day 21 → DOM Selectors Day 22 → DOM Manipulation Day 23 → Events Day 24 → Event Bubbling Day 25 → Event Delegation Day 26 → Async JavaScript (Next Post) Follow for more 🚀 #JavaScriptSimplified #javascript #webdevelopment #coding #programming #learninpublic #100DaysOfCode #frontenddevelopment #devcommunity #codingjourney #softwaredeveloper #techcommunity #dailylearning #codeeveryday
To view or add a comment, sign in
-
🚀 JavaScript Simplified Series — Day 35 Prototypes are powerful… But let’s be honest 😅 👉 Syntax thoda confusing lagta hai 👉 Hard to read 👉 Not beginner friendly What if we could write the same thing in a **clean and simple way?** 🤔 --- ## 🔥 Solution → Classes --- ## 🔹 What are Classes? Classes are just a **clean syntax over prototypes** 👉 Same power 👉 Better readability --- ## 🔹 Without Class (Old Way) ```javascript id="clx1" function User(name) { this.name = name } User.prototype.greet = function() { console.log("Hello " + this.name) } let u1 = new User("Abhay") u1.greet() ``` --- ## 🔹 With Class (Modern Way 😎) ```javascript id="clx2" class User { constructor(name) { this.name = name } greet() { console.log("Hello " + this.name) } } let u1 = new User("Abhay") u1.greet() ``` 👉 Same result 👉 Cleaner code --- ## 🔹 Adding More Methods ```javascript id="clx3" class User { constructor(name) { this.name = name } greet() { console.log("Hello " + this.name) } sayBye() { console.log("Goodbye") } } ``` --- ## 🔥 Real Life Example Think of a **blueprint 🏗️** 👉 Class = blueprint 👉 Object = actual building Same design → multiple objects --- ## 🔥 Simple Summary Class → cleaner syntax Constructor → initialize values Methods → behavior --- ### 💡 Programming Rule **Write code that humans can read. Classes make code cleaner.** --- If you want to learn JavaScript in a **simple and practical way**, you can follow these YouTube channels: • Rohit Negi --- 📌 Series Progress Day 1 → What is JavaScript Day 2 → Variables & Data Types Day 3 → Type Conversion & Operators Day 4 → Truthy & Falsy + Comparison Operators Day 5 → If Else + Switch + Ternary Day 6 → Loops Day 7 → Break + Continue + Nested Loops Day 8 → Functions Basics Day 9 → Arrow + Default + Rest Parameters Day 10 → Callback & Higher Order Functions Day 11 → Arrays Basics Day 12 → Array Methods Day 13 → Array Iteration Day 14 → Advanced Array Methods Day 15 → Objects Basics Day 16 → Object Methods + this Day 17 → Object Destructuring Day 18 → Spread & Rest Day 19 → Advanced Objects Day 20 → DOM Introduction Day 21 → DOM Selectors Day 22 → DOM Manipulation Day 23 → Events Day 24 → Event Bubbling Day 25 → Event Delegation Day 26 → Async JavaScript Day 27 → Promises Day 28 → Async / Await Day 29 → Fetch API Day 30 → Event Loop Day 31 → Scope Day 32 → Hoisting Day 33 → Closures Day 34 → Prototypes Day 35 → Classes Day 36 → Inheritance (Next Post) --- Follow for more 🚀 #JavaScriptSimplified #javascript #webdevelopment #coding #programming #learninpublic #100DaysOfCode #frontenddevelopment #devcommunity #codingjourney #softwaredeveloper #techcommunity #dailylearning #codeeveryday
To view or add a comment, sign in
-
-
Back to Basics: Mastering JavaScript Higher-Order Functions Deep-dived into JavaScript's functional programming side today! I've been working on a logic-based task to analyze financial transactions. Instead of using traditional loops, I leveraged .map() and .reduce() to process data and extract meaningful insights like Total Income, Total Expenses, and Overall Balance. It’s amazing how clean and readable the code becomes when you utilize these ES6 features effectively. Here is a quick look at the logic I used: const transactions = [ { id: 1, category: 'Groceries', amount: 50, date: '2026-04-01', type: 'expense' }, { id: 2, category: 'Salary', amount: 2000, date: '2026-04-05', type: 'income' }, { id: 3, category: 'Electronics', amount: 300, date: '2026-04-10', type: 'expense' }, { id: 4, category: 'Groceries', amount: 30, date: '2026-04-12', type: 'expense' }, { id: 5, category: 'Freelance', amount: 500, date: '2026-04-15', type: 'income' } ]; function transaction(){ const a= transactions.map((c)=>{ const f=c?.amount return f }) const m=a.reduce((total,c)=>{ const g=total+c return g }) const z=`total amount is :${m}` console.log(z) //total expense const b=transactions.map((t)=>{ if(t?.type==='expense') { const a= t?.amount return a; } else{ return 0 } }) const totalExpense=b.reduce((total,a)=>{ return total+a }) console.log(` total expense is ${totalExpense}`) //total Income const i=transactions.map((t)=>{ if(t?.type==='income') { const a= t?.amount return a; } else{ return 0 } }) const totalIncome=i.reduce((total,a)=>{ return total+a }) console.log(`totalincome is :${totalIncome}`) } transaction() Key Takeaways: .map() – for extracting specific data points like amounts. .reduce() – for transforming an array into a single summary value. Optional Chaining (?.) – to ensure the code doesn't break if a property is missing. Still learning and improving every day! How do you prefer to handle data transformations? Let's discuss in the comments. #JavaScript #WebDevelopment #CodingLife #CleanCode #Programming #MERNStack #LearningEveryday
To view or add a comment, sign in
-
🚀 JavaScript Simplified Series — Day 36 You created a class… Now imagine 👇 You want another class with: 👉 Same properties 👉 Same methods 👉 Plus some extra features Will you rewrite everything again? ❌ That’s inefficient 😵 --- ## 🔥 Solution → Inheritance --- ## 🔹 What is Inheritance? Inheritance allows one class to: 👉 **Reuse properties & methods of another class** --- ## 🔹 Example ```javascript id="inh1" class User { constructor(name) { this.name = name } greet() { console.log("Hello " + this.name) } } class Admin extends User { deleteUser() { console.log("User deleted") } } let admin = new Admin("Abhay") admin.greet() admin.deleteUser() ``` 👉 Output: Hello Abhay User deleted --- ## 🔍 What’s happening? 👉 `Admin` inherited from `User` 👉 So it gets `greet()` automatically 👉 Plus its own method --- ## 🔹 super keyword ```javascript id="inh2" class Admin extends User { constructor(name, role) { super(name) this.role = role } } ``` 👉 `super()` calls parent constructor --- ## 🔥 Real Life Example Think of a **family 👨👩👧** 👉 Parent → basic traits 👉 Child → inherits + adds new traits --- ## 🔥 Simple Summary extends → inheritance super → parent constructor Reuse → no duplication --- ### 💡 Programming Rule **Don’t rewrite code. Reuse it with inheritance.** --- If you want to learn JavaScript in a **simple and practical way**, you can follow these YouTube channels: • Rohit Negi • Hitesh Choudhary (Chai aur Code) --- 📌 Series Progress Day 1 → What is JavaScript Day 2 → Variables & Data Types Day 3 → Type Conversion & Operators Day 4 → Truthy & Falsy + Comparison Operators Day 5 → If Else + Switch + Ternary Day 6 → Loops Day 7 → Break + Continue + Nested Loops Day 8 → Functions Basics Day 9 → Arrow + Default + Rest Parameters Day 10 → Callback & Higher Order Functions Day 11 → Arrays Basics Day 12 → Array Methods Day 13 → Array Iteration Day 14 → Advanced Array Methods Day 15 → Objects Basics Day 16 → Object Methods + this Day 17 → Object Destructuring Day 18 → Spread & Rest Day 19 → Advanced Objects Day 20 → DOM Introduction Day 21 → DOM Selectors Day 22 → DOM Manipulation Day 23 → Events Day 24 → Event Bubbling Day 25 → Event Delegation Day 26 → Async JavaScript Day 27 → Promises Day 28 → Async / Await Day 29 → Fetch API Day 30 → Event Loop Day 31 → Scope Day 32 → Hoisting Day 33 → Closures Day 34 → Prototypes Day 35 → Classes Day 36 → Inheritance Day 37 → Modules (Next Post) --- Follow for more 🚀 #JavaScriptSimplified #javascript #webdevelopment #coding #programming #learninpublic #100DaysOfCode #frontenddevelopment #devcommunity #codingjourney #softwaredeveloper #techcommunity #dailylearning #codeeveryday
To view or add a comment, sign in
-
-
Mastering JavaScript Symbols & Signs Every programming language has its own “alphabet.” In JavaScript, symbols and signs are the building blocks that give meaning to your code. Here’s a quick guide to the most common ones — and why they matter: --- 🔹 Grouping & Structure - Parentheses ( ) → Function parameters, grouping expressions, invoking functions - Curly braces { } → Code blocks (loops, conditionals), object literals - Square brackets [ ] → Arrays, element access --- 🔹 Statement Control - Semi-colon ; → End of a statement (optional, but recommended) - Comma , → Separate items in arrays, objects, or function arguments - Period . → Access object properties and methods --- 🔹 Operators You Can’t Ignore - Assignment = → Assign values - Comparison → ==, ===, !=, !==, >, <, >=, <= - Arithmetic → +, -, , /, %, * - Logical → &&, ||, ! - Increment/Decrement → ++, -- - Ternary ? : → Shorthand for if...else --- 🔹 Strings & Comments - Concatenation + → Join strings together - Comments → // single-line, / / multi-line --- 💡 Why This Matters Understanding these symbols isn’t just about syntax — it’s about writing cleaner, more predictable code. Whether you’re debugging, building automation scripts, or teaching others, these signs are the “grammar” of JavaScript. #JavaScript #CodingBasics #WebDevelopment #SoftwareTesting #Automation
To view or add a comment, sign in
-
Mastering JavaScript Symbols & Signs Every programming language has its own “alphabet.” In JavaScript, symbols and signs are the building blocks that give meaning to your code. Here’s a quick guide to the most common ones — and why they matter: --- 🔹 Grouping & Structure - Parentheses ( ) → Function parameters, grouping expressions, invoking functions - Curly braces { } → Code blocks (loops, conditionals), object literals - Square brackets [ ] → Arrays, element access --- 🔹 Statement Control - Semi-colon ; → End of a statement (optional, but recommended) - Comma , → Separate items in arrays, objects, or function arguments - Period . → Access object properties and methods --- 🔹 Operators You Can’t Ignore - Assignment = → Assign values - Comparison → ==, ===, !=, !==, >, <, >=, <= - Arithmetic → +, -, , /, %, * - Logical → &&, ||, ! - Increment/Decrement → ++, -- - Ternary ? : → Shorthand for if...else --- 🔹 Strings & Comments - Concatenation + → Join strings together - Comments → // single-line, / / multi-line --- 💡 Why This Matters Understanding these symbols isn’t just about syntax — it’s about writing cleaner, more predictable code. Whether you’re debugging, building automation scripts, or teaching others, these signs are the “grammar” of JavaScript. #JavaScript #CodingBasics #WebDevelopment #SoftwareTesting #Automation
To view or add a comment, sign in
-
Most developers think inheritance in JavaScript works like traditional OOP. It doesn’t. And that confusion leads to messy, over-engineered code. JavaScript uses prototypal inheritance — not classical inheritance. 👉 Objects inherit directly from other objects. 💡 There are 3 main ways inheritance works in JavaScript: 🔹 1. Prototypal Inheritance (Core Concept) const animal = { speak() { console.log("Makes a sound"); } }; const dog = Object.create(animal); dog.bark = function () { console.log("Bark"); }; dog.speak(); // inherited dog.bark(); // own method ✔ Simple ✔ Flexible ✔ Native to JS 🔹 2. Constructor Function Inheritance function Animal(name) { this.name = name; } Animal.prototype.speak = function () { console.log(this.name + " makes noise"); }; function Dog(name) { Animal.call(this, name); // inherit properties } Dog.prototype = Object.create(Animal.prototype); const d = new Dog("Tommy"); d.speak(); ✔ More structured ✔ Used in older codebases 🔹 3. Class-based Inheritance (ES6) class Animal { constructor(name) { this.name = name; } speak() { console.log(this.name + " makes noise"); } } class Dog extends Animal { bark() { console.log("Bark"); } } const dog = new Dog("Rocky"); dog.speak(); dog.bark(); ✔ Cleaner syntax ✔ Easier to read ❗ Still uses prototypes under the hood ⚡ The truth most people miss: Even with classes… 👉 JavaScript is STILL prototype-based. Classes are just syntactic sugar. 🧠 The real upgrade: Stop thinking: “Which syntax should I use?” Start thinking: “How does inheritance actually work under the hood?” Because once you understand prototypes… You don’t just write code— you understand it. What confused you more in JavaScript—closures, promises, or prototypes? 👇 #JavaScript #WebDevelopment #Programming #Frontend #Coding #SoftwareEngineering
To view or add a comment, sign in
-
Just wrote a blog on the "new" keyword in JS Under the hood, new follows a precise process: • Creates a new empty object • Links it to the constructor’s prototype • Binds this to that object • Executes the constructor function • Returns the final instance If you're learning JavaScript or revisiting fundamentals, this will sharpen your understanding 👇 https://lnkd.in/gEitS7KJ #JavaScript #WebDevelopment #Frontend #Programming #Coding #LearnInPublic #Developers #SoftwareEngineering
To view or add a comment, sign in
-
The return Statement, Pocket Knowledge for the Era of Vibe Coding You can vibe code an entire app today. Prompt your way from idea to deployment without writing a single function from scratch. And that’s fine. But when undefined stares back at you and the AI-generated function isn’t behaving, you need to know why. Not from another prompt. From your own head. This isn’t a tutorial on return. It’s a briefing. Four things you carry with you as a developer. 1. A function is a private world When JavaScript runs a function, it creates a closed room. Variables built inside live inside. Instructions run inside. Nothing walks out on its own, no matter how clearly you can see the value sitting there. function buildLink() { const link = “https://lnkd.in/eH3akRij"; } const result = buildLink(); console.log(result); // undefined That link exists. It’s just trapped. return is the only door out of that room. No return nothing comes back. Ever. 2. return does two things at once This is the one most people miss. return doesn’t just send a value out. It stops the function dead at the same moment. Not pauses. Stops. Everything below it in that block becomes invisible to JavaScript, it won’t run, it won’t error, it will simply never execute. function buildCdnLink(packageName, version, filePath) { let link = `https://lnkd.in/eUAsawyz; if (filePath) { return; // door opens, function dies HERE link = link + “/” + filePath; // dead code. JavaScript never sees this. } return link; } return fired with nothing after it. The function answered with silence. JavaScript calls that silence undefined. Two things. Simultaneously. Send the value out, kill the function. Miss the second one and you’ll spend hours debugging code that looks completely fine. 3. Placement is everything Because return kills the function the moment it runs, where you put it is as important as what you put after it. The rule is simple, do the work first, return at the bottom. // wrong, return fires before the work is done function buildCdnLink(packageName, version, filePath) { let link = `https://lnkd.in/eUAsawyz; if (filePath) { return; // too early, work never happens link = link + “/” + filePath; } return link; } // right, work happens first, return hands it back at the end function buildCdnLink(packageName, version, filePath) { let link = `https://lnkd.in/eUAsawyz; if (filePath) { link = link + “/” + filePath; // work done first } return link; // then the door opens } Every time you write a function, ask yourself, have I done everything before I open the door? If the answer is no, return is in the wrong place. Read the full piece on Medium; [https://lnkd.in/eEu9frGx] #JavaScript #WebDevelopment #Programming #LearnToCode #SoftwareDevelopment #VibeCoding #OpenSource
To view or add a comment, sign in
-
-
Wrote a new blog on Map and Set in JavaScript Covering: - Why Objects and Arrays are not always enough - Limitations of traditional key-value storage - How Map enables true key flexibility - The uniqueness guarantee of Set - Map vs Object (practical differences) - Set vs Array (performance + behavior) - When to use Map and Set in real projects If you're building real-world applications, choosing the right data structure is not optional. It directly impacts performance, readability, and scalability. https://lnkd.in/gkTF3N-M Hitesh Choudhary Chai Aur Code Piyush Garg Akash Kadlag Jay Kadlag Nikhil Rathore #javascript #webdevelopment #frontend #coding #programming #softwaredevelopment #100daysofcode #learninpublic
To view or add a comment, sign in
Explore related topics
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