JavaScript Practice: Flattening an Array (Without flat()) Today, I worked on a simple but important JavaScript exercise: flattening an array. The goal was to transform a mixed array (numbers + nested arrays) into a single-level array, without using Array.prototype.flat(), to better understand loops and array manipulation. 💡 What this exercise helped me practice: Iterating over arrays with for...of Detecting arrays using Array.isArray() Using the spread operator (...) to merge elements Writing clean and readable logic ✅ Example output: [1, 2, 3, 4, 25, 6, 7, 5] This kind of small exercise is great for building strong fundamentals in JavaScript and improving problem-solving skills step by step. 📂 You can find the full code here: 👉 https://lnkd.in/ej4fNeZs #JavaScript #CodingPractice #WebDevelopment #LearningInPublic #Frontend #ProblemSolving #GitHub
Flattening a Mixed JavaScript Array Without flat()
More Relevant Posts
-
https://lnkd.in/diyD-KU3 slice vs splice in JavaScript — a small concept that makes a big difference. Understanding which array methods mutate data and which don’t is crucial for writing predictable and bug-free code, especially in frontend frameworks. Sharing a quick visual breakdown for anyone revising JavaScript fundamentals. Which array method confused you the most when you started? #JavaScriptDevelopers #FrontendDevelopment #ProgrammingBasics #DevelopersOfLinkedIn #ContinuousLearning
slice vs splice explained 🍕A quick JavaScript concept every developer must know.
https://www.youtube.com/
To view or add a comment, sign in
-
✨ Understanding var, let, and const in JavaScript ✨ One of the first hurdles for beginners in JavaScript is figuring out when to use var, let, or const. While they all declare variables, the differences matter for clean, bug-free code: 🔹var – Function-scoped, allows redeclaration, and can lead to unexpected behavior due to hoisting. Best avoided in modern code. 🔹 let – Block-scoped, can be updated but not redeclared in the same scope. Ideal for variables whose values change over time. 🔹 const – Block-scoped, must be initialized at declaration, and cannot be reassigned. Perfect for constants or values that should remain fixed. Mastering these keywords is a small step that makes a big difference in writing clean, predictable, and modern JavaScript🚀 #JavaScript #WebDevelopment #FrontendDevelopment #CodingTips #LearnToCode #CleanCode #DeveloperLife #TechCommunity
To view or add a comment, sign in
-
🔒 JavaScript Closures — If you’re learning JavaScript, closures might sound scary at first. But in real projects, you’re already using them — maybe without realizing it. 📱 Think of a closure like a saved contact in your phone Even if the call ends, the number is still remembered. 🎒 Or like a backpack — whatever you put inside stays with you wherever you go, just like a closure carries its variables. 👉 In JavaScript, an inner function remembers variables from its outer scope, even after the outer function has finished running. 💡 That’s why closures help with: • Preserving state • Keeping data private • Writing cleaner, more predictable code ⚡ You’ll often see closures in event handlers, callbacks, and React hooks — even if you don’t notice them at first. #javascript #closures #webdevelopment #beginners #codingjourney
To view or add a comment, sign in
-
-
🚀 Day 6 – Daily Tech Dose (JavaScript) 💡 Today’s Topic: JavaScript Hoisting Quick Question 👇 What will be the output? console.log(a); var a = 10; ✅ Answer: undefined 🧠 Why? • JavaScript hoists variable declarations (not initializations). • var a is moved to the top, but = 10 stays where it is. • So at console.log(a), a exists but has no value yet → undefined. ⚠️ Try the same with let or const and you’ll get a ReferenceError. 💬 Interview Tip • Hoisting applies to functions too (function declarations are fully hoisted). • Prefer let / const to avoid confusing bugs. ⸻ 🔖 Hashtags #JavaScript #WebDevelopment #Frontend #Programming #CodingInterview #LearnJS #TechDaily #100DaysOfCode #VivekVishwakarma Want Day 7 next? 😄
To view or add a comment, sign in
-
-
👀 This JavaScript Output Looks TOO Simple… Or Is It? At first glance, this feels like basic JavaScript 😄 But answers in comments will be very different 👀 let x; console.log(x); console.log(typeof x); x = null; console.log(x); console.log(typeof x); No loops. No functions. No tricks. Just undefined and null — two words that confuse almost everyone. 🤔 Why this question is interesting Very beginner-friendly Tests core JS fundamentals Common interview question Easy to attempt → high participation Simple code, deep concept 💬 Your Turn Comment your answers like this 👇 Line 1 → Line 2 → Line 3 → Line 4 → ⚠️ Don’t run the code. Answer based on your understanding. I will post the correct output + simple explanation in the evening. 📌 This post is to understand JavaScript basics clearly, not to confuse beginners. #JavaScript #LearnJS #FrontendDevelopment #CodingInterview #TechWithVeera #WebDevelopment
To view or add a comment, sign in
-
-
🤔 Quick question: How does JavaScript know which function to run next? While diving deeper into JavaScript, I realized something simple but powerful sits at the core of execution: the Call Stack. When I first heard “call stack,” it sounded scary. Turns out… it’s just a stack of function calls 👇 function first() { console.log("First"); second(); } function second() { console.log("Second"); } first(); 💡 What happens behind the scenes? - first() is pushed onto the call stack - Inside first(), second() is called → pushed on top - second() finishes → popped off the stack - first() finishes → popped off the stack Execution always happens from the top of the stack. Takeaway: JavaScript uses a Call Stack to keep track of function execution. Functions are pushed when called and popped when finished — simple, but critical to understand everything that comes next (async, event loop, errors). 👉 Have you ever debugged a “Maximum call stack size exceeded” error? #JavaScript #WebDevelopment #FullStack #LearningInPublic
To view or add a comment, sign in
-
🚨 “Why did my JavaScript object suddenly break?” I remember thinking: “Object keys are just variable names… easy.” That single assumption cost me hours of debugging 😵💫 Most beginners don’t realize this early: 👉 JavaScript does not treat object keys the way we visually see them. Internally, every object key is stored as a string 🧠 So when a key contains: • spaces • special characters JavaScript needs it to be written explicitly as a string. If you skip this rule, the code: • throws errors • behaves unexpectedly • makes objects feel “random” They’re not random. Your mental model is incomplete. 📌 One tiny syntax rule = hours of confusion saved #JavaScript #LearningInPublic #WebDevelopment #FrontendDevelopment #Debugging
To view or add a comment, sign in
-
-
🚀 Day 885 of #900DaysOfCode ✨ 5 Important Object Methods in JavaScript Objects are at the core of JavaScript — and knowing how to work with them efficiently can make your code cleaner, more readable, and easier to maintain. In today’s post, I’ve covered 5 essential JavaScript object methods that every developer should be familiar with. These methods help you handle data more effectively and simplify common object-related operations in real-world applications. If you want to strengthen your JavaScript fundamentals and write more confident code, this post is for you. 👇 Which object method do you use most often? Let me know in the comments! #Day885 #learningoftheday #900daysofcodingchallenge #FrontendDevelopment #WebDevelopment #JavaScript #React #CodingCommunity #Objects
To view or add a comment, sign in
-
🤔 Quick JavaScript quiz! What do you think this logs? console.log(x); var x = 10; If you said undefined, you’re right ✅ Welcome to JavaScript hoisting. Hoisting means JS moves declarations (not values) to the top of their scope before running your code. Now try this 👇 console.log(y); let y = 10; 💥 Error! let and const are hoisted too, but live in the Temporal Dead Zone until declared. 👉 Rule of thumb: Hoisting is real, but clean, top-down code saves you from bugs. What tripped you up more when you were learning JS — var or let? 👀 #JavaScript #Frontend #WebDev #LearningInPublic
To view or add a comment, sign in
-
🚀 JavaScript Fundamentals: Small Differences, Big Impact While practicing JavaScript patterns and loops, I clearly understood how small changes can completely affect output and logic. 🔹 Difference between let and var in for loops Using var: Function scoped Variable leaks outside the loop Can cause unexpected bugs (especially in async code) Allows redeclaration Using let: Block scoped Limited only to the loop block Safer and predictable Preferred in modern JavaScript 👉 Best practice: Always use let in loops. 🔹 Difference between console.log inside vs outside inner loop console.log INSIDE inner loop: Prints while the row is being built Executes multiple times per row Produces triangle / step-by-step patterns console.log OUTSIDE inner loop: Prints after completing one row Executes once per row Produces square, rectangle, or aligned patterns 🧠 Key Learnings Loop behavior depends on scope Pattern output depends on where you print Understanding fundamentals avoids logical mistakes in interviews 🙏 Thanks to my mentor sanjeev ch for guiding me to focus on logic, not just output. #JavaScript #WebDevelopment #CodingFundamentals #LearningJavaScript
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