✨ Today I learned something simple but powerful in JavaScript — Removing duplicates & flattening arrays! These two tricks help keep your data clean and easy to work with. 🚀 🔹 Remove Duplicates from an Array Using Set (fast & clean): const numbers = [1, 2, 2, 3, 4, 4, 5]; const uniqueNumbers = [...new Set(numbers)]; console.log(uniqueNumbers); // [1, 2, 3, 4, 5] --- 🔹 Flatten a Nested Array Using flat(): const nested = [1, [2, [3, 4]], 5]; const flatArray = nested.flat(2); console.log(flatArray); // [1, 2, 3, 4, 5] --- 🔥 These small improvements help write cleaner, more readable code. If you're learning JavaScript, definitely try these out! #JavaScript #Learning #WebDevelopment #CodingJourney #100DaysOfCode
"JavaScript Tricks: Remove Duplicates & Flatten Arrays"
More Relevant Posts
-
Understanding Conditional Statements in JavaScript" Today I learned about Conditional Statements in JavaScript — they help our code make decisions based on conditions. It’s like teaching our program to think before acting! 💭 Here are the main types 👇 1️⃣ if statement – runs code if a condition is true let age = 18; if (age >= 18) { console.log("You are eligible to vote!"); } 2️⃣ if...else statement – runs one block if true, another if false let temp = 25; if (temp > 30) { console.log("It's hot outside!"); } else { console.log("The weather is pleasant."); } 3️⃣ else if ladder – checks multiple conditions let marks = 85; if (marks >= 90) console.log("Grade A"); else if (marks >= 75) console.log("Grade B"); else console.log("Keep trying!"); 4️⃣ switch statement – a cleaner way for multiple conditions let day = "Monday"; switch (day) { case "Monday": console.log("Start of the week!"); break; case "Friday": console.log("Weekend is near!"); break; default: console.log("Just another day."); } Conditional statements help control the flow of logic — making code smart and dynamic! ⚡ #JavaScript #WebDevelopment #ConditionalStatements #LearnToCode #FrontendDevelopment #CodingJourney #100DaysOfCode #ProgrammingBasics #TechLearning #DeveloperCommunity
To view or add a comment, sign in
-
Understanding Variables in JavaScript Today, I explored one of the core fundamentals of JavaScript — Variables. Variables act as containers for storing data, and they play a major role in how programs handle, update, and manage information. JavaScript provides three ways to declare variables: var, let, and const. Each behaves differently in terms of scope, reassignment, and hoisting — making it important to choose the right one based on the requirement. 🔍 Key Points I Learned ✔️ Variables store dynamic values like numbers, strings, arrays, objects, etc. ✔️ var → function-scoped, older way, can lead to unexpected behavior ✔️ let → block-scoped, ideal for values that change ✔️ const → block-scoped, used for fixed values (cannot be reassigned) ✔️ ES6 improved code reliability by introducing let and const Building strong fundamentals like variables helps in writing cleaner, predictable, and modern JavaScript code. 🚀 Grateful to my mentor Sudheer Velpula for guiding and encouraging consistent learning. 🙌 #JavaScript #Variables #WebDevelopment #Frontend #CodingJourney #ES6 #ProgrammingBasics #LearnJavaScript #TechLearning #DeveloperCommunity
To view or add a comment, sign in
-
-
#Day2Nov #dailylearning 💡 What is a Closure in JavaScript? A closure is created when a function remembers and accesses variables from its outer function — even after the outer function has finished executing. In simple words, 👉 A closure lets a function use values that were in scope when it was created. 🧠 Example: function outer() { let count = 0; function inner() { count++; console.log(count); } return inner; } const counter = outer(); counter(); // 1 counter(); // 2 Here, inner() still remembers the variable count from outer() — that’s a closure! 🔍 Why Closures are Useful: To remember data between function calls To create private variables Used in data hiding and function factories #masiverse #WebDevelopment #Javascript #learning
To view or add a comment, sign in
-
Today I learned three powerful JavaScript methods: map(), filter(), and reduce() 🧠 These methods make working with arrays super efficient — instead of writing long loops, you can do everything in just a few lines of clean code! map() → transforms each element filter() → filters elements based on condition reduce() → reduces all elements into a single value (like sum or total) Learning how they work together really changed the way I think about data manipulation in JS 😍 #JavaScript #FrontendDevelopment #CodingJourney #WebDevelopment #LearningEveryday
To view or add a comment, sign in
-
🚀 Day 19 of 30 Days of JavaScript – LeetCode Problem: 1207. Unique Number of Occurrences Today’s challenge was all about checking whether the number of occurrences of each value in an array is unique. ✅ My Approach 1️⃣ Count occurrences I used a for...of loop to count how many times each element appears in the array. 2️⃣ Store frequency results This gives me an object holding the occurrence count of every unique item. 3️⃣ Convert to a Set I extracted the values and converted them into a Set using new Set(), since a set automatically removes duplicates. 4️⃣ Compare values Arrays and sets can’t be directly compared, so I converted both to strings using JSON.stringify() to compare their datatype + values. 5️⃣ Return result If both match, I return true; otherwise, false. #JavaScript #LeetCode #30DaysOfCode #codingjourney #developerlife
To view or add a comment, sign in
-
-
🚀 If you still use var in JavaScript... you’re living in 2010! Let’s talk about one of the most underrated but powerful differences every JS developer must understand 👇 When I was learning JavaScript, I thought var and let were just different ways to declare a variable... But the day I understood why let replaced var, everything changed. 💡 Here’s the truth: 🔹 var is function-scoped, gets hoisted, and even worse — it attaches itself to the window object in browsers! Meaning: Anyone can access or even overwrite your variables globally 😱 var token = "mySecret"; console.log(window.token); // 🫣 Accessible to everyone Now imagine storing API keys, tokens, or user info like that... Yes — that’s not just bad practice; it’s a security risk. 🔒 Why let (and const) are the heroes: ✅ Block-scoped (safe inside { }) 🚫 Not attached to window ⚡ No accidental redeclaration 🔥 Prevents bugs caused by hoisting They bring safety, clarity, and modern standards to your code. When you finally understand this while learning JS, you realize why every developer, framework, and company today avoids var completely. It’s not just about syntax — it’s about secure, predictable, and professional JavaScript. 💪 #JavaScript #WebDevelopment #CodingTips #FrontendDevelopment #MERNStack #LearnCoding #WebDeveloper #CodeNewbie #TechCommunity #DeveloperLife #CodingJourney #LetsCode #100DaysOfCode
To view or add a comment, sign in
-
-
Day 69 of #100daysCode Ever wondered how JavaScript thinks? 🤔 It’s all about Variables, Data Types, and Operators! These 3 concepts might seem simple, but they’re the secret to how JS handles everything — from text to numbers to logic. Swipe through my carousel to learn the basics in a fun, visual way 🎨✨ #JavaScript #CodingJourney #FrontendDevelopment #LearnToCode #WomenInTech
To view or add a comment, sign in
-
🚀 Day 26 — JavaScript Foundations: var, let, const & Core Interactions 💻⚡ Today’s session deepened my understanding of JavaScript fundamentals — how data is declared, stored, and interacted with at the most essential level. 💡 Topics Covered: • Difference between var, let, and const — scope, re-declaration, and modern best practices • Hands-on with prompt( ), alert( ), and console.log( ) — understanding how data flows between user and browser • Real-world logic on how browsers interpret and execute scripts • Setting the foundation for DOM interactions and event-driven programming ✨ Each line of code felt like unlocking a new layer of control — from dynamic user input to precise debugging insights. The fundamentals may look simple, but they form the core muscle of every advanced JS concept. This is where true coding confidence begins. 💪 #JavaScript #FrontendDevelopment #FullStackDeveloper #CodingJourney #WebDevelopment #LearnInPublic #BuildInPublic #WebProgramming #SoftwareEngineering #Innovation #TechLearning #JavaScriptFundamentals #ProgrammingBasics #6MonthChallenge
To view or add a comment, sign in
-
-
🧮 Day 42 | In-Built Objects in JavaScript Explored Math and Date objects in JavaScript today — the foundation of many logical operations. 🧠 Learned about: • Math constants & methods (PI, round, random, pow, sqrt) • Date creation, formatting & manipulation • Time control using get and set methods ✨ Key Takeaway: JS comes packed with powerful tools — we just need to know how to use them right! 🔗 GitHub: https://lnkd.in/dtdU9-zZ #WebDevelopment #JavaScript #CodingJourney #Frontend
To view or add a comment, sign in
-
-
🚫 Stop Saying “Variables Are Moved to the Top” The Real Explanation of Hoisting in JavaScript “Variables are moved to the top of their scope” — a phrase I’ve heard countless times in JavaScript tutorials. After working extensively with JS, I realized this explanation often causes confusion. The real story is more nuanced. 🔍 What Hoisting Actually Is Hoisting is not the JavaScript engine moving code around. Instead, during the compilation phase, JavaScript: - Scans the scope - Allocates memory for variable and function declarations - Sets up how each variable behaves when accessed 🟡 var vs let / const During Hoisting var - Memory is allocated - Initialized with undefined - Accessible before declaration (but returns undefined) let and const - Memory is reserved - Not initialized Stay in the Temporal Dead Zone (TDZ) until the actual declaration Accessing them early throws a ReferenceError Example console.log(a); // undefined var a = 10; console.log(b); // ReferenceError let b = 20; ⭐ Key Points to Remember - Only declarations are hoisted — not assignments - Function declarations are fully hoisted and available before they appear in code - let and const use the TDZ (Temporal Dead Zone), which is essential to understand for debugging and writing reliable code
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