Quick JS Brain Teaser: What happens when you try to add a property to a primitive string value? let str = "hello"; str.customProp = "world"; console.log(str.customProp); Options: A) "world" B) undefined C) TypeError D) "helloworld" Does this match your expectations? Drop your answer in the comments and explain the autoboxing behavior! Let's discuss how JavaScript handles primitives vs objects. #JavaScript #JavaScriptInterviewQuestion #JavaScriptFundamentals
JavaScript Autoboxing: Primitive String Value
More Relevant Posts
-
Today I learned a fundamental concept in JavaScript the difference between map() and filter(). At first, both methods felt similar because they iterate over arrays. But the key difference is in their purpose: map() transforms every element and returns a new array of the same length. filter() returns only the elements that satisfy a given condition, which may reduce the array size. Understanding this clearly makes array manipulation much more intuitive and improves problem-solving speed. Sometimes the basics, when deeply understood, create the biggest improvements. How do you usually approach array transformations in real-world projects? Would love to hear your thoughts.
To view or add a comment, sign in
-
JavaScript TDZ — Where are var, let, and const stored? 🧠 When JS runs, it creates an Execution Context ⚙️ with two memory areas: 1️⃣ Global Object Environment 🌍 → var variables go here → attached to the global object (like window in browsers) → auto-initialized with undefined ✅ 2️⃣ Script / Lexical Environment 📦 → let and const go here → block-scoped memory space → memory reserved but not initialized 🚫 (TDZ ⏳) That’s why: var before declaration → undefined let/const before declaration → error ⛔ JS separates them to enforce block scope and reduce bugs 🛡️ #JavaScript #JSCore #ExecutionContext
To view or add a comment, sign in
-
𝗧𝘄𝗼 𝗧𝘆𝗽𝗲𝘀 𝗢𝗳 𝗥𝗲𝘁𝘂𝗿𝗻 𝗜𝗻 𝗔𝗿𝗿𝗼𝘄 𝗙𝘂𝗻𝗰𝗍𝗶𝗼𝗻𝘀 When you work with arrow functions in JavaScript, you can return values in two ways: implicit return and explicit return. You use implicit return when the function has a single expression. The result of that expression is automatically returned. - You define a function with a single expression. - The result of that expression is returned. For example: const add = (a, b) => a + b; console.log(add(2, 3)); // Output:
To view or add a comment, sign in
-
Week 5 – JavaScript ☕💻 Topics : • Arrays – map(), filter(), reduce() • Objects & their methods • IIFE and little overview of closures. • Pure vs Impure functions Earlier, these were just methods. Now I’m starting to understand how everything connects. JS feels comfortable right now… but I know complexity is coming. Preparing for that. Staying consistent. Chai Aur Code #WebDevCohort2026
To view or add a comment, sign in
-
-
Arrays are a special type of objects. The typeof operator in JavaScript returns "object" for arrays. You can have objects in an Array. You can have functions in an Array. You can have arrays in an Array: myArray[0] = Date.now; myArray[1] = myFunction; myArray[2] = myCars; In JavaScript, arrays use numbered indexes. In JavaScript, objects use named indexes. Arrays are a special kind of objects, with numbered indexes. Array.isArray(fruits); return true or false.
To view or add a comment, sign in
-
My browser survived today’s JavaScript experiments I made it: • shout “Hello World” • ask users for their numbers • use confirm() + if/else logic to control actions • manipulate the DOM (background color) code:https://lnkd.in/d6AKKvcH
To view or add a comment, sign in
-
Quick JS Brain Teaser: What will be the output of this code? async function test() { console.log('1'); setTimeout(() => { console.log('2'); }, 0); await Promise.resolve(); console.log('3'); setTimeout(() => { console.log('4'); }, 0); console.log('5'); } test(); console.log('6'); A) 1, 6, 3, 5, 2, 4 B) 1, 3, 5, 6, 2, 4 C) 1, 6, 2, 3, 5, 4 D) 1, 2, 3, 4, 5, 6 Drop your answer in the comments and explain why! Does this match your expectations for execution context questions? #JavaScript #JavaScriptInterviewQuestion #JavaScriptFundamentals
To view or add a comment, sign in
-
🧠 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗚𝗮𝗿𝗯𝗮𝗴𝗲 𝗖𝗼𝗹𝗹𝗲𝗰𝘁𝗶𝗼𝗻 (𝗚𝗖) — 𝗤𝘂𝗶𝗰𝗸 𝗜𝗻𝘀𝗶𝗴𝗵𝘁 JavaScript automatically manages memory using 𝗚𝗮𝗿𝗯𝗮𝗴𝗲 𝗖𝗼𝗹𝗹𝗲𝗰𝘁𝗶𝗼𝗻 ✅ Most JS engines (like V8) use the 𝗠𝗮𝗿𝗸-𝗮𝗻𝗱-𝗦𝘄𝗲𝗲𝗽 𝗮𝗹𝗴𝗼𝗿𝗶𝘁𝗵𝗺: ✅ 𝗠𝗮𝗿𝗸: GC starts from root references (global scope, current stack, closures) and marks all 𝗥𝗲𝗮𝗰𝗵𝗮𝗯𝗹𝗲 objects. ✅ 𝗦𝘄𝗲𝗲𝗽: 𝗨𝗻𝗿𝗲𝗮𝗰𝗵𝗮𝗯𝗹𝗲 objects are removed from memory. ⚠️ 𝗖𝗼𝗺𝗺𝗼𝗻 𝗺𝗲𝗺𝗼𝗿𝘆 𝗹𝗲𝗮𝗸 𝗿𝗲𝗮𝘀𝗼𝗻𝘀: ✔ Unremoved event listeners ✔ Uncleared setInterval() / timers ✔ Closures holding large references ✔ Accidental global variables Understanding GC helps build 𝗳𝗮𝘀𝘁𝗲𝗿, 𝘀𝘁𝗮𝗯𝗹𝗲, 𝗮𝗻𝗱 𝗺𝗲𝗺𝗼𝗿𝘆-𝗲𝗳𝗳𝗶𝗰𝗶𝗲𝗻𝘁 apps 🚀 #JavaScript #FrontendDevelopment #Performance #MemoryManagement #V8 #WebDevelopment #SoftwareEngineering
To view or add a comment, sign in
-
How JavaScript engines actually handle arrays, and there’s a lot of hidden logic going on. ⚙️ The main thing is the difference between Packed (continuous) and Holey (arrays with empty gaps). Here is what I learned: SMI is the best: Arrays with only small integers are the most optimized. One-way downgrade: If you add a float or string to an integer array, the engine downgrades its optimization. Even if you remove that item later, it doesn't go back to being as fast as it was. Holes are costly: When JS hits an empty gap, it has to check all the way up the prototype chain to find a value. It’s one of the most expensive operations in the engine. A simple tip I learned: Avoid using "new Array(3)" because it creates holes immediately. Starting with [ ] keeps things much more optimized. #LearningInPublic #Javascript #WebDev
To view or add a comment, sign in
-
🤯 Ever used a variable before declaring it… and it still worked? - That’s called Hoisting. But wait… JavaScript doesn’t actually “move” your code. Here’s what really happens 👇 🧠 What is Hoisting? During the creation phase of execution, JavaScript: - Registers variable declarations - Registers function declarations - Allocates memory before running your code 🔹 How var behaves console.log(a); var a = 10; Output: undefined Why? Because var is hoisted and initialized with undefined. 🔹 How let and const behave console.log(b); let b = 20; ❌ ReferenceError Because let and const are hoisted — but not initialized (Temporal Dead Zone). 🔹 Function Declarations greet(); function greet() { console.log("Hello"); } ✅ Works perfectly Function declarations are fully hoisted.
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