✅ Why This Output Is NOT What Most Expect This morning’s code was: function sum(a, b, c = 10) {} console.log(sum.length); 💡 Correct Output 2 🧠 Simple Explanation (This Is the Key) In JavaScript: 👉 function.length returns the number of parameters BEFORE the first default value Let’s look at the parameters: function sum(a, b, c = 10) {} a → counted ✅ b → counted ✅ c = 10 → ❌ NOT counted So JavaScript counts only: a, b → 2 parameters That’s why: sum.length → 2 🎯 Key Takeaways (Interview Gold) function.length ≠ total parameters It counts only parameters without defaults Defaults stop the count immediately Useful for introspection & frameworks 📌 This behavior surprises many people because it’s rarely used directly. 💬 Your Turn Did you expect 2 or 3? 😄 Comment “Didn’t know this 🤯” or “Already knew 👍” #JavaScript #LearnJS #FrontendDevelopment #CodingInterview #Functions #TechWithVeera #WebDevelopment
JavaScript function.length counts only non-default parameters
More Relevant Posts
-
🧠 This JavaScript Function Call Looks Normal… But Think Carefully 👀 Most people focus on the value. Very few notice how the function is called 😄 function show() { return "Hello"; } console.log(show); console.log(show()); Same function. Two console logs. Completely different outputs. 🤔 Why this question is interesting Tests function reference vs function execution Very common beginner confusion Asked indirectly in interviews Looks simple → answers vary a lot Almost everyone comments confidently 💬 Your Turn Comment your answers like this 👇 Line 1 → Line 2 → Why? → ⚠️ Don’t run the code. Answer based on understanding. I Will post the correct output + simple explanation in the evening. 📌 This post is to understand JavaScript behavior, not to trick anyone. #JavaScript #LearnJS #FrontendDevelopment #CodingInterview #TechWithVeera #WebDevelopment
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 Function Looks Normal… But the Output Isn’t Most people think parameters and arguments are the same. This question proves they are not 👀 function demo(a, b) { arguments[0] = 100; console.log(a); } demo(10, 20); No async. No defaults. No tricks. Still… answers vary a LOT 😄 🤔 Why this question is interesting Tests arguments vs parameters Shows old JS behavior many forget Common interview discussion point Looks beginner-friendly Seniors often explain it wrongly 💬 Your Turn Comment your answer 👇 Output → Why? → ⚠️ Please don’t run the code. Answer based on understanding. I will post the correct output + very clear explanation in the evening. 📌 This post is to understand JavaScript behavior, not recommended modern patterns. #JavaScript #LearnJS #FrontendDevelopment #CodingInterview #TechWithVeera #WebDevelopment
To view or add a comment, sign in
-
-
const user = { name: 'Munsif', print: () => console.log(this.name) }; user.print(); If you think it prints "Munsif"... we need to talk. The `this` keyword is the silent killer of clean code. It changes based on *how* you call it, not *where* you write it. I just dropped a massive deep dive on my blog: "Demystifying the JavaScript 'this' Keyword." I peel back the layers on: 🔹 The 4 binding rules every dev must memorize 🔹 The exact reason the code above fails (and how to fix it) 🔹 The magic of `.bind()`, `.call()`, and `.apply()` 🔹 Tricky interview questions that trip everyone up Don't let context bugs haunt your PRs anymore. Link to the full breakdown: https://lnkd.in/gWMGP5Kn (The answer to the snippet is `undefined`. My blog explains why! 😉) #JavaScript #CodingChallenge #Frontend #DeveloperLife #JS
To view or add a comment, sign in
-
-
Have you ever done this in JavaScript? 🤨 console.log(x); // no error var x = 5; console.log(y); // ❌ ReferenceError let y = 10; Feels weird, right? 😅 Here’s the real reason 👇 JavaScript creates memory for all variables before execution starts. But it treats them differently: ✅ var gets hoisted and initialized to undefined, so accessing it before declaration just prints undefined. ⚠️ let (and const) are also hoisted, but NOT initialized. They live in a temporary dead zone until the declaration line is reached - so trying to use them early throws a ReferenceError. In simple terms: this is hoisting - but only var gets a default value upfront. 💡 If you’re learning JavaScript fundamentals, mastering this will save you from tons of weird bugs. 👇 Comment “HOISTED” and I’ll drop quick interview questions on hoisting! #JavaScript #WebDevelopment #JSTips #Coding #Tech
To view or add a comment, sign in
-
-
🛑 This JavaScript Output Confuses Almost Everyone (Even Seniors) Looks very simple, right? Most people answer this confidently… and still get it wrong 😄 console.log(isNaN("hello")); console.log(Number.isNaN("hello")); console.log(isNaN(NaN)); console.log(Number.isNaN(NaN)); No loops. No async. Just NaN. Yet… answers in comments will be all over the place 👀 🤔 Why this question is interesting Tests real understanding of NaN Shows difference between global vs strict checking Very common interview question Looks easy → causes overconfidence Everyone comments something 💬 Your Turn Comment your answers like this 👇 Line 1 → Line 2 → Line 3 → Line 4 → ⚠️ Don’t run the code. Answer based on understanding. I will post the correct output + clear explanation in the evening. 📌 This post is to understand JavaScript behavior, not to judge anyone. #JavaScript #LearnJS #FrontendDevelopment #CodingInterview #TechWithVeera #WebDevelopment
To view or add a comment, sign in
-
-
🧠 This JavaScript Condition Looks OBVIOUS… But Is It? 👀 Most people answer this in 2 seconds 😄 And that’s where the mistake happens. let a = []; if (a) { console.log("Yes"); } else { console.log("No"); } No functions. No loops. Just one if. Still… comments will be very different 👀 🤔 Why this question is interesting Tests truthy vs falsy Many think [] is falsy Very common interview trap Easy to read, tricky to reason Everyone feels confident to comment 💬 Your Turn Comment your answer 👇 Output → Why? → ⚠️ Don’t run the code. Answer based on understanding. I Will post the correct output + simple explanation in the evening. 📌 This post is to strengthen JavaScript basics, not to confuse beginners. #JavaScript #LearnJS #FrontendDevelopment #CodingInterview #TechWithVeera #WebDevelopment
To view or add a comment, sign in
-
-
🧠 This JavaScript Array Code Looks IDENTICAL… But the Output Is NOT Most people think slice and splice behave the same. This question proves how dangerous that assumption is 👀 let arr = [1, 2, 3, 4]; let a = arr.slice(1, 3); let b = arr.splice(1, 2); console.log(a); console.log(b); console.log(arr); Same array. Similar parameters. Very different behavior. This question gets maximum comments 😄 🤔 Why this question is very interesting Tests slice vs splice (classic interview trap) Shows mutation vs non-mutation Easy to attempt Hard to explain clearly Seniors double-check before answering 💬 Your Turn Comment your answers like this 👇 a → b → arr → ⚠️ Don’t run the code. Answer based on understanding. I Will post the correct output + very clear explanation in the evening. 📌 This post is to understand JavaScript array behavior, not to confuse beginners. #JavaScript #LearnJS #FrontendDevelopment #CodingInterview #ArrayMethods #TechWithVeera #WebDevelopment
To view or add a comment, sign in
-
-
𝗜 thought debounce and throttle were timing tricks. Turns out they’re memory problems. This week I explored debounce and throttle, and both are really about the same idea: 👉 controlling time by remembering state Debounce waits until events stop, then runs once Throttle runs at a fixed rate, no matter how noisy the events are Under the hood, it’s all about closures: storing timers remembering the last call deciding when a function is allowed to run I implemented both in vanilla JavaScript and then again in React using hooks (useRef, useEffect) to see how memory behaves across renders. Turns out: Performance isn’t about doing more — it’s about doing things at the right time. Still learning, but this clicked for me 💡 Would love to hear how others explain debounce vs throttle. #JavaScript #React #WebPerformance #LearningInPublic #Closures
To view or add a comment, sign in
-
-
Today I explored some powerful JavaScript concepts that level up how code actually behaves behind the scenes: ✅ this keyword – Understanding how context works inside objects and functions. ✅ try...catch – Handling errors properly so programs don’t crash unexpectedly. ✅ Arrow Functions (=>) – Writing cleaner and shorter functions (and how this behaves differently inside them). ✅ setTimeout() – Running code after a delay. ✅ setInterval() – Running code repeatedly at fixed intervals. These topics helped me understand how JavaScript handles execution, timing, and errors — which are super important for real-world applications. Slowly building strong fundamentals 💻🔥 #JavaScript #WebDevelopment #LearningInPublic #100DaysOfCode #FrontendDevelopment
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
Did not know this