Day 20/30 – Check if Object or Array is Empty in JavaScript Challenge 🧐 | JSON Logic 💻🚀 🧠 Problem: Given an object or array (from JSON.parse()), return whether it is empty. Rules: An empty object → has no key-value pairs An empty array → has no elements ✨ What this challenge teaches: Difference between objects vs arrays Understanding JSON structures Checking data safely before processing This logic is heavily used in: ⚡ API response validation ⚡ Form handling ⚡ Conditional rendering (React) ⚡ Backend data checks Test with: {} [] { name: "JS" } [1,2,3] Small logic — big real-world importance 💡 💬 How would you handle nested empty objects? #JavaScript #30DaysOfJavaScript #CodingChallenge #JSON #JSLogic #WebDevelopment #LearnToCode #CodeEveryday #DeveloperJourney #Programming #TechCommunity #LeetCode Check empty object JavaScript Check empty array JS JavaScript JSON validation JavaScript object methods LeetCode JavaScript solution JS interview questions Beginner JavaScript practice Daily coding challenge
Check Empty Object or Array in JavaScript
More Relevant Posts
-
🚀 **JavaScript: var vs let vs const (Every Developer Should Know This)** Understanding the difference between `var`, `let`, and `const` is one of the most important fundamentals in JavaScript. Let’s simplify it 👇 --- 🔴 **var** • Function scoped • Can be **reassigned** • Can be **redeclared** • Hoisted and initialized as `undefined` ```javascript var x = 10; x = 20; // ✅ allowed var x = 30; // ✅ allowed ``` ⚠️ Old JavaScript way. Avoid using `var` in modern code. --- 🟢 **let** • Block scoped `{ }` • Can be **reassigned** • ❌ Cannot be redeclared in the same scope • Hoisted but in **Temporal Dead Zone (TDZ)** ```javascript let y = 10; y = 20; // ✅ allowed let y = 30; // ❌ Error ``` ✔ Best for variables that will change. --- 🟣 **const** • Block scoped • ❌ Cannot be reassigned • ❌ Cannot be redeclared • Hoisted with **Temporal Dead Zone** ```javascript const z = 10; z = 20; // ❌ Error ``` ✔ Best for constants. --- 🎯 **Best Practice** ✔ Use **const by default** ✔ Use **let when value changes** ❌ Avoid **var** This makes your code **cleaner, safer, and predictable.** --- 💬 Interview Question: What is **Temporal Dead Zone (TDZ)** in JavaScript? Comment your answer 👇 --- #JavaScript #WebDevelopment #FrontendDevelopment #Coding #Programming #SoftwareEngineering #LearnToCode #DeveloperTips #JS #TechCommunity
To view or add a comment, sign in
-
-
But I can still change const even though it is immutable, Const a = [] a.push(7) Above code is completely valid. Can anyone explain that .. comment below 👇
Immediate Joiner - Software Developer | Full Stack Web Developer | NODE JS | REACT JS | PHP | JS | GITHUB | PYTHON | DJANGO | REST API | MYSQL | MONGO DB | FLASK | WORDPRESS
🚀 **JavaScript: var vs let vs const (Every Developer Should Know This)** Understanding the difference between `var`, `let`, and `const` is one of the most important fundamentals in JavaScript. Let’s simplify it 👇 --- 🔴 **var** • Function scoped • Can be **reassigned** • Can be **redeclared** • Hoisted and initialized as `undefined` ```javascript var x = 10; x = 20; // ✅ allowed var x = 30; // ✅ allowed ``` ⚠️ Old JavaScript way. Avoid using `var` in modern code. --- 🟢 **let** • Block scoped `{ }` • Can be **reassigned** • ❌ Cannot be redeclared in the same scope • Hoisted but in **Temporal Dead Zone (TDZ)** ```javascript let y = 10; y = 20; // ✅ allowed let y = 30; // ❌ Error ``` ✔ Best for variables that will change. --- 🟣 **const** • Block scoped • ❌ Cannot be reassigned • ❌ Cannot be redeclared • Hoisted with **Temporal Dead Zone** ```javascript const z = 10; z = 20; // ❌ Error ``` ✔ Best for constants. --- 🎯 **Best Practice** ✔ Use **const by default** ✔ Use **let when value changes** ❌ Avoid **var** This makes your code **cleaner, safer, and predictable.** --- 💬 Interview Question: What is **Temporal Dead Zone (TDZ)** in JavaScript? Comment your answer 👇 --- #JavaScript #WebDevelopment #FrontendDevelopment #Coding #Programming #SoftwareEngineering #LearnToCode #DeveloperTips #JS #TechCommunity
To view or add a comment, sign in
-
-
🌐 Learning Frontend Day 14: JavaScript Data Types JavaScript data types are the building blocks of all logic in web development. They define how values are stored, manipulated, and interpreted. 🔑 Key Data Types in JS: Primitive Types String → "Hello World" Number → 42, 3.14 Boolean → true / false Null → intentional empty value Undefined → variable declared but not assigned Symbol → unique identifiers BigInt → large integers beyond Number limits Non-Primitive (Reference) Types Object → collections of key-value pairs Array → ordered lists [1,2,3] Function → reusable blocks of code #FrontendDevelopment #JavaScript #WebDevelopment #LearningJourney #CodingLife #100DaysOfCode #TechSkills #DeveloperCommunity #JSBasics #CodeNewbie
To view or add a comment, sign in
-
-
🚀 **Scope in JavaScript (Every Developer Must Understand This)** Scope determines **where a variable is accessible** in your code. If you don’t understand scope, you’ll eventually face unexpected bugs. Let’s break it down 👇 --- ## 🌍 1️⃣ Global Scope Variables declared outside any function are accessible everywhere. ```js let name = "Abhishek"; function greet() { console.log(name); } ``` ✔ Accessible inside functions ✔ Accessible across the file --- ## 🧠 2️⃣ Function Scope (`var`) `var` is function-scoped. ```js function test() { var message = "Hello"; } console.log(message); // ❌ Error ``` It exists only inside the function. --- ## 📦 3️⃣ Block Scope (`let` / `const`) `let` and `const` are block-scoped. ```js if (true) { let age = 25; } console.log(age); // ❌ Error ``` Accessible only inside `{ }` --- ## ⚠ Common Mistake with `var` ```js if (true) { var age = 25; } console.log(age); // 25 😱 ``` Why? Because `var` ignores block scope and leaks outside the block. --- ## 🎯 Best Practice ✅ Use `const` by default ✅ Use `let` when value needs to change ❌ Avoid `var` in modern JavaScript --- Mastering scope makes you stronger in: ✔ Closures ✔ Event Loop ✔ Asynchronous JavaScript ✔ Interviews --- 💬 What should I explain next? 1️⃣ Closures 2️⃣ Event Loop #JavaScript #FrontendDevelopment #WebDevelopment #Programming #CodingInterview #JSConcepts #SoftwareEngineering #FullStackDeveloper #LearnToCode #DeveloperTips #100DaysOfCode #TechCommunity
To view or add a comment, sign in
-
-
💡 The JavaScript .sort() Surprise: Why [10, 2, 5] isn't [2, 5, 10] Ever had code that worked perfectly until the numbers got bigger? Check out this classic JavaScript quirk. 😅 In the screenshot, you'll notice: ✅ [3, 1, 4, 2].sort() results in [1, 2, 3, 4] (Perfect!) ❌ [10, 2, 5].sort() results in [10, 2, 5] (Wait... what?) The "Why" behind the weirdness: By default, JavaScript’s .sort() method converts elements into strings and compares their UTF-16 code unit values. It’s not looking at the numeric value; it’s looking at the characters. Just like "Apple" comes before "Banana," the string "10" comes before "2" because "1" comes before "2" in the dictionary. The Fix: To sort numbers correctly, you need to provide a compare function. This tells JavaScript exactly how to handle the math: let arr2 = [10, 2, 5]; // The correct way to sort numerically: arr2.sort((a, b) => a - b); console.log(arr2); // [2, 5, 10] tandard behavior is great for strings, but for data structures and algorithms (DSA), the compare function is your best friend! Have you ever been bitten by a default behavior in a programming language? Let’s hear your "favorite" bug in the comments! 👇 #JavaScript #WebDevelopment #CodingTips #Programming #SoftwareEngineering #DSA #LearningToCode
To view or add a comment, sign in
-
-
JavaScript Array Methods Every Developer Should Know 👨💻 Arrays are one of the most commonly used data structures in JavaScript. When you understand array methods well, your code becomes cleaner, shorter, and easier to maintain. Here are some important methods every developer should know: 🔹 map() – Transforms each element in an array and returns a new array. 🔹 filter() – Selects elements that match a specific condition. 🔹 reduce() – Converts the entire array into a single value (great for totals, counts, and data processing). 🔹 find() – Returns the first element that matches a condition. 🔹 some() – Checks if at least one element satisfies a condition. 🔹 every() – Checks if all elements satisfy a condition. Mastering these methods helps you write more efficient JavaScript and improves your problem-solving skills in real projects. Which JavaScript array method do you use the most? 🤔 #JavaScript #WebDevelopment #FrontendDeveloper #Coding #Programming #100DaysOfCode
To view or add a comment, sign in
-
-
😂 **JavaScript Be Like…** “This is my favorite language.” Until… ```js "11" + 1 // "111" "11" - 1 // 10 ``` And suddenly everyone is sweating 😅 --- ## 💡 What’s Happening Here? 🔹 `"11" + 1` → `+` triggers **string concatenation** → Result: `"111"` 🔹 `"11" - 1` → `-` forces **numeric conversion** → Result: `10` --- ### 🚀 Welcome to JavaScript Type Coercion JavaScript automatically converts types depending on the operator. ✔ `+` → Can concatenate strings ✔ `-`, `*`, `/` → Force numeric conversion This flexibility is powerful… But if you don’t understand it, it becomes dangerous. --- ### 🎯 Lesson: Always be aware of data types. Use `Number()`, `String()`, or `parseInt()` explicitly when needed. Because in JavaScript… It works. But not always the way you expect 😄 --- 💬 Have you ever been confused by JS type coercion? #JavaScript #FrontendDevelopment #WebDevelopment #ProgrammingHumor #CodingLife #JSConcepts #SoftwareEngineering #FullStackDeveloper #LearnToCode #TechCommunity #DeveloperMemes #100DaysOfCode
To view or add a comment, sign in
-
-
When working with data in JavaScript, arrays are everywhere. But storing values is only half the job. Most of the time we need to process that data. For example: Transform values Remove unwanted items Calculate totals JavaScript provides powerful built-in methods that make this much easier: map() → transform each value in an array filter() → select values that match a condition reduce() → combine values into a single result In my latest blog, I explain these methods using simple examples and show how they compare with traditional loops. https://lnkd.in/dQsy3i78 If you're learning JavaScript fundamentals, these are methods you’ll use almost every day. #javascript #webdevelopment #coding #learninpublic #chaicode
To view or add a comment, sign in
-
-
🚨 JavaScript Array Methods: slice() vs splice() — Mutation vs Non-Mutation Sometimes bugs come from misunderstanding built-in methods. Two array methods developers often confuse: slice() and splice() 🧠 Key difference slice() → does NOT modify the original array Returns a new array splice() → modifies the original array Can remove, replace, or insert elements ⚠️ This small difference can cause unexpected bugs in: • React state updates • Shared data structures • Functional programming 💡 Rule to remember slice() → copy splice() → modify #JavaScript #FrontendDevelopment #WebDevelopment #SoftwareEngineering #CleanCode #ReactJS
To view or add a comment, sign in
-
-
Today I solved a classic JavaScript problem: Removing duplicates from an array without using built-in methods like Set. Instead of relying on shortcuts, I implemented the logic manually using nested loops to fully understand how duplicate detection works internally. 🧠 Problem Given an array like: Copy code [1, 2, 2, 3, 4, 3] Return: [1, 2, 3, 4] 🔍 My Approach I created a new empty array called unique to store only distinct values. I looped through each element of the original array. For every element, I checked whether it already exists inside the unique array. If it does not exist, I pushed it into the unique array. If it already exists, I skipped it. This approach uses: An outer loop to iterate over the original array An inner loop to check for existing values A boolean flag (exists) to track duplicates 💡 Why I Chose This Approach While JavaScript provides a built-in way to remove duplicates using: [...new Set(arr)] I intentionally avoided it to: Strengthen my understanding of loops Improve my logical thinking Practice writing interview-style solutions Understand time complexity and algorithm behavior ⏱ Time Complexity O(n²) — because for each element, we may check the entire unique array. 🎯 Key Learning This problem helped me understand: Nested loop logic How duplicate detection works internally The importance of loop structure and placement Debugging mistakes like incorrect loop conditions Building strong fundamentals makes advanced concepts easier later. Consistency > shortcuts 💪 #JavaScript #ProblemSolving #WebDevelopment #100DaysOfCode #FrontendDeveloper #DSA #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