👀 This JavaScript Code Looks Normal… But the Output Surprises Many Most people say “easy” when they see this 👇 But the last line makes many stop and think 🤔 function greet() { return "Hello"; } console.log(typeof greet); console.log(typeof greet()); console.log(greet instanceof Object); No async. No arrays. No tricks. Still… the output is not what everyone expects. 🧠 Why this question matters Tests functions as first-class citizens Helps understand functions vs function calls Very common interview concept Looks simple but checks real JS fundamentals 💬 Your Turn Comment your answers like this 👇 Line 1 → ? Line 2 → ? Line 3 → ? Try answering without running the code 🤓 I will post the correct output + simple explanation in the evening 📌 Note: This post is to understand JavaScript behavior, not to confuse beginners #JavaScript #FrontendDevelopment #LearnJS #CodingInterview #Functions #TechWithVeera #WebDevelopment #100DaysOfCode
JavaScript Function Behavior: Surprising Output Explained
More Relevant Posts
-
🧠 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
-
-
👀 This JavaScript Code Looks Harmless… But the Output Isn’t What You Think Most people read this and say “easy” But many answer it wrong — even experienced devs. let user = { name: "Veera" }; console.log(user.name); console.log(user.age); console.log("age" in user); console.log(user.hasOwnProperty("age")); No arrays. No async. No tricky syntax. Just a simple object 👀 Still… the last two lines confuse many. 🧠 Why this question matters Tests object property access Shows the difference between: value being undefined property not existing Very common interview concept Looks simple but checks real JS understanding 💬 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 post is to understand JavaScript behavior, not to confuse beginners #JavaScript #FrontendDevelopment #LearnJS #CodingInterview #Objects #TechWithVeera #WebDevelopment #100DaysOfCode
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
-
-
🛑 Read Twice Before Answering , JavaScript Thinks Faster Than We Do This looks harmless. But many answers go wrong because of how JavaScript evaluates parameters 👀 function test(a = 10, b = a) { console.log(a, b); } test(5); No tricks. No loops. No async. Still… people pause here 😄 🤔 Why this question is interesting Tests default parameters Tests evaluation order Looks beginner-friendly Still makes seniors think twice Very common interview logic 💬 Your Turn Comment your answer like this 👇 a → b → ⚠️ Please 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 production patterns. #JavaScript #LearnJS #FrontendDevelopment #CodingInterview #TechWithVeera #WebDevelopment
To view or add a comment, sign in
-
-
JavaScript Hoisting — explained simply 🧠⬆️ Hoisting is one of the most confusing JavaScript topics, but the idea is actually very simple. Before executing code, JavaScript: ✔ Scans the file ✔ Allocates memory for variables and functions Important points: • Function declarations are fully hoisted • var is hoisted but initialized as undefined • let & const are hoisted but not accessible (TDZ) Simple rule to remember: Hoisting moves declarations to the top, not values. Understanding hoisting helps avoid “undefined” and reference errors 🚀 #javascript #frontenddeveloper #webdevelopment #coding #learningjavascript #reactjs #softwareengineering
To view or add a comment, sign in
-
-
🧠 Shortcuts don’t break JavaScript. Misunderstanding fundamentals does. I tried using throw new Error() inside a ternary operator, expecting it to behave like an if/else. ❌ Didn’t work. 🧠 The reason (important): • throw is a statement, not an expression • Ternary operators only accept expressions Small syntax rule. Big “aha” moment. 💡 What this reinforces: ✔️ Fundamentals matter more than clever tricks ✔️ JavaScript rewards clarity over shortcuts ✔️ Tiny misunderstandings can cause long debugging sessions These are the kinds of details that separate code that runs from code that’s reliable. 👀 Your turn: What’s the smallest JavaScript mistake that once wasted the most time for you? 💬 Drop it in the comments let’s learn from each other. 📩 And if you’re building or reviewing a Node.js/JavaScript codebase and want it clean, predictable, and production-ready feel free to DM me. #JavaScript #NodeJS #WebDevelopment #SoftwareEngineering #CodingLife #DeveloperLearning #CleanCode #Debugging #ProgrammingTips #TechCommunity #BuildInPublic
To view or add a comment, sign in
-
-
Ever written code that should have thrown an error, but instead just returned undefined? 🤔 Welcome to JavaScript Hoisting. It’s one of those fundamental concepts that often catches developers off guard during interviews or debugging sessions. As illustrated in the visual below, the JavaScript engine doesn't execute your code exactly top-to-bottom as you write it. It has a "creation phase" first. The crucial rule to remember (highlighted in red): 🚨 Only declarations are hoisted, not initializations. This is why accessing a var before its assignment gives you undefined, while accessing a function declaration works perfectly fine. Understanding this "under-the-hood" behavior is key to writing predictable JS code. Have you ever spent hours debugging an issue caused by hoisting? Let me know in the comments! 👇 #JavaScript #WebDevelopment #CodingTips #ProgrammingConcepts #JS #SoftwareEngineering #TechCareers #FrontendDeveloper
To view or add a comment, sign in
-
-
JavaScript Event Loop – how async code really works 🚀 JavaScript is single-threaded, yet it handles asynchronous operations efficiently using the Event Loop. Understanding the interaction between the Call Stack, Web APIs, and task queues helps in writing better, non-blocking code. Microtasks (Promises) always execute before callback queue tasks — a small detail with big impact. #JavaScript #EventLoop #AsyncJS #WebDevelopment #Learning JavaScript #AsyncJavaScript#EventLoop#Promises #AsyncAwait
To view or add a comment, sign in
-
-
JavaScript: Fetch API, Promises & Async/Await 🌐⚙️ These concepts are must-know for handling API calls and async operations in modern JavaScript. 🔹 Fetch API Used to make HTTP requests. It returns a Promise. 🔹 Promises Handle async results with 3 states: pending → resolved → rejected 🔹 Async/Await A cleaner and more readable way to work with Promises using try/catch. 🧠 Practice Tip: ✔ Fetch data from a public API ✔ Rewrite it using async/await ✔ Handle errors properly Save this if you’re learning JavaScript 🚀 #JavaScript #WebDevelopment #AsyncJavaScript #FetchAPI #FrontendDevelopment #LearnToCode #DevTips
To view or add a comment, sign in
-
-
`𝗳𝗼𝗿𝗘𝗮𝗰𝗵` 𝗹𝗼𝗼𝗸𝘀 𝗶𝗻𝗻𝗼𝗰𝗲𝗻𝘁. 𝗨𝗻𝘁𝗶𝗹 𝘆𝗼𝘂 𝗺𝗶𝘅 𝗶𝘁 𝘄𝗶𝘁𝗵 𝗮𝘀𝘆𝗻𝗰 𝗰𝗼𝗱𝗲. Many async bugs don’t throw errors. They just quietly do the wrong thing. `forEach` doesn’t wait. It doesn’t respect `await`. So your logic runs out of order while your code 𝗹𝗼𝗼𝗸𝘀 correct. This is one of those traps that separates “working code” from 𝗿𝗲𝗹𝗶𝗮𝗯𝗹𝗲 𝗰𝗼𝗱𝗲. If you write async JavaScript, this is worth a pause. 𝗥𝗲𝗮𝗱 𝗺𝗼𝗿𝗲: https://lnkd.in/dww_BYP2 #JavaScript #AsyncProgramming #CleanCode #WebDevelopment #DeveloperMindset
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
Function String True