🧠 This JavaScript Output Looks Impossible… But It Runs! Read carefully 👇 Don’t rush. console.log(Math.max()); console.log(Math.min()); console.log(Math.max(1, 2, 3)); console.log(Math.max([1, 2, 3])); No loops. No async. No tricky operators. Just Math. Still… the output surprises almost everyone 😄 🤔 Why this question feels different Hardly anyone practices empty arguments Shows how JS handles missing values Mixes numbers vs arrays in a subtle way Looks very beginner-friendly, but seniors pause 💬 Your Turn Comment your answers like this 👇 Line 1 → Line 2 → Line 3 → Line 4 → Try answering without running the code 🤓 I will post the correct output + simple explanation in the evening. 📌 Note: This is to understand JavaScript behavior, not to encourage confusing code. #JavaScript #FrontendDevelopment #LearnJS #CodingInterview #TechWithVeera #WebDevelopment #100DaysOfCode
JavaScript Math.max() Function Behavior
More Relevant Posts
-
map vs forEach in JavaScript 🧠 Both are used to loop over arrays, but they are NOT the same. forEach 👇 • Used to perform an action • Does NOT return a new array • Mostly used for side effects (console, API call) map 👇 • Used to transform data • ALWAYS returns a new array • Very common in React rendering Simple rule to remember: Need a new array? → use map Just doing something? → use forEach Understanding this avoids many beginner mistakes 🚀 #javascript #frontenddeveloper #webdevelopment #coding #learningjavascript #reactjs #softwareengineering
To view or add a comment, sign in
-
-
Read the full guide here: 👉 https://lnkd.in/g8xPc26Y Stop memorizing JavaScript Closures. Start understanding them. 🧠 Closures are more than just an interview question—they are the "secret sauce" behind data privacy and advanced functional patterns. Think of a closure as a function carrying a "backpack" of variables from where it was born. 🎒 Even after the outer function finishes, that backpack stays alive. In my latest post, I break down: - Lexical Scope (The environment) - Variable Capture (The "backpack" logic) - Practical Use Cases (Beyond the theory) - Check out the deep dive and level up your JS game today! 🚀 #javascript #webdev #coding #frontend #softwareengineering
To view or add a comment, sign in
-
-
Ever wondered how objects in JavaScript use features they never created? 🤔 From where do the methods and properties of objects actually come? They come from something called Prototype ✨ Think of it like this: You don’t own a pen 🖊️ But your friend does. When you need it, you borrow it 🤝 JavaScript works the same way. If an object doesn’t have something, it borrows it from its prototype. 🧱 Object Example const person = { name: "Bushra" }; console.log(person.hasOwnProperty("name")); // true We never wrote hasOwnProperty. So where did it come from? It comes from Object.prototype. JavaScript searches like this: person → Object.prototype → null 📦 Array Example const numbers = [1, 2, 3]; numbers.push(4); numbers.pop(); We never created push or pop. They come from Array.prototype. JavaScript searches like this: numbers → Array.prototype → Object.prototype → null #JavaScript #LearnJS #WebDevelopment #Frontend #CodingJourney #Programming #TechLearning #DeveloperLife #100DaysOfCode #JSBasics
To view or add a comment, sign in
-
SSR is more than just "fast loading." 🚀 It’s a balance between Initial Visibility and Interactivity. In my latest study session, I broke down the Next.js cycle: ✅ Server renders HTML (Next.js = Node.js server) ✅ Browser displays static content (FCP) ✅ Assets download & JS executes ✅ React "Hydrates" the DOM ✅ Page becomes interactive (TTI) Understanding these metrics (TTFB, FCP, TTI) helps us build applications that not only look fast but also feel fast. Check out my diagram below! 👇 #nextjs #programming #performance #javascript #typescript #react #ai #ssr #ia
To view or add a comment, sign in
-
-
🧠 This JavaScript Output Looks TOO Easy… Until You Think Properly Most people answer this confidently. Some answer fast. Many answer wrong let count = 1; function test() { if (!count) { let count = 10; } console.log(count); } test(); No async. No arrays. No operators. Just if, let, and one variable 👀 Still… this one separates guessing from understanding. 🤔 Why this question is interesting Tests scope Tests block vs outer variable Tests truthy / falsy Very common interview-style confusion Looks simple → causes overconfidence 💬 Your Turn Comment your answer like this 👇 Output → Why? → ⚠️ Please don’t run the code. Answer based on understanding. I will post the correct output + a very clear explanation in the evening 📌 Note: This post is meant to learn how JavaScript behaves, not to judge anyone’s skill #JavaScript #FrontendDevelopment #LearnJS #CodingInterview #TechWithVeera #WebDevelopment #100DaysOfCode
To view or add a comment, sign in
-
-
✅ 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
To view or add a comment, sign in
-
-
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
To view or add a comment, sign in
-
-
📌 *I learned how JavaScript Scope really works — and it changed how I write code!* 💡 Understanding *scope* is key to mastering JS logic, especially when dealing with nested functions and variable access. Here’s what clicked for me: 🔍 *Scope* defines where your variables are accessible. 📚 *Lexical Scope* means JavaScript decides scope at the time of writing, not during execution. 🔗 *Scope Chaining* is how JS looks outward from the inner function to find a variable — step by step through parent scopes. 🔁 *Variable Lookup* happens top-down. If not found locally, JS checks outer scopes until it finds it (or throws ReferenceError). 🧠 *Once you grasp how scope works — no more confusion around let, var, const or nested functions!* 💬 Have you ever been stuck because of variable scope issues? Let’s grow by learning smart. 🚀 #JavaScript #WebDevelopment #ScopeInJS #LexicalScope #JSConcepts #FrontendDeveloper #DeveloperJourney #CodeTips #LearnToCode #CodeWithWaleed #WaleedDevsigner #SalyianTech #ItMask #AsyncJS #WebDevBasics #100DaysOfCode #ProgrammingMadeSimple #TechCommunity #SelfTaughtProgrammer
To view or add a comment, sign in
-
-
💠 JavaScript slice() Method — Explained Simply The slice() method is used to extract a portion of an array or string without modifying the original data. It returns a new array or string, making it a non-mutating and safe operation. 🔍 Key Characteristics 🔸 Does not mutate the original array or string 🔸 Supports negative indexes 🔸 Commonly used for copying arrays, pagination, and sub-list creation 👉 Real-World Use Case 🔹 In React applications, slice() is often used for: 🔹 Pagination 🔹 Displaying partial lists 🔹 Maintaining immutability during state updates 💡 Why it matters 🔹 In React and modern JavaScript, immutability is key. 🔹 slice() helps maintain clean, predictable state updates. #JavaScript #FrontendDevelopment #ReactJS #WebDevelopment #CodingTips #LearnJavaScript #Programming
To view or add a comment, sign in
-
-
💻 JavaScript code should read like a story, not a puzzle. We've all seen the "Pyramid of Doom." You need to login, then get a user, then get their posts. Before you know it, you are ten brackets deep and can't find the way out. In our latest article entitled "The Secret Life of JavaScript: The Promise", we look at the evolution of async code: ✅ Callbacks: The nesting nightmare. ✅ Promises: The flat chain (The IOU). ✅ Async/Await: The "pause" button that doesn't freeze the browser. See how to turn your staircase logic into a straight line. 👉 Read it on Medium: https://lnkd.in/gmXQryaZ #JavaScript #Async #Coding #SoftwareDevelopment
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
Line 1 → -Infinity Line 2 → Infinity Line 3 → 3 Line 4 → NaN Correct way to use array with Math.max console.log(Math.max(...[1, 2, 3])); output: 3