Zum Hauptinhalt springen
LIVE
CVSS 6.5CVE-2026-111315 | The Smaily Connect plugin for WordPress is vulnerable to Insecure Direct Object Reference in versions up to, and including, 3.24.0 This is due to the smaily_get_edit_user_id() function reading an attacker-controlled $_GET['user_id'] parameter without performing any ownership or capability check, and then feeding that id into smaily_get_userdata() (which calls get_user_meta()) when rendering the WooCommerce My Account 'edit-account' form via the smaily_print_CVSS 6.4CVE-2026-137713 | Webmin through 2.670 before ae8feb1 allows XSS via an SVG attachment in a mail queue, relevant if an authenticated user uploads an SVG document and an administrator views it.CVSS 6.9CVE-2026-137678 | A security vulnerability has been detected in code-projects Online Job Portal 1.0. Affected by this issue is some unknown functionality of the file Admin/InsertUser.php. Such manipulation of the argument txtUserName/txtPassword leads to sql injection. The attack can be launched remotely. The exploit has been disclosed publicly and may be used.CVSS 5.3CVE-2026-137703 | Flask-AppBuilder before 5.3.1 contains a path traversal vulnerability in ImageManager.save_file that allows authenticated users to write image files outside IMG_UPLOAD_FOLDER via unsanitized multipart filenames. Attackers with add or edit permission on a ModelView with an ImageColumn can upload filenames containing ../ segments to create or overwrite image files like static assets.CVSS 6.1CVE-2026-130039 | The LiteSpeed Cache plugin for WordPress is vulnerable to Stored Cross-Site Scripting via the 'REQUEST_URI' parameter in all versions up to, and including, 7.9.3 due to insufficient input sanitization and output escaping. This makes it possible for unauthenticated attackers to inject arbitrary web scripts in pages that will execute whenever a user accesses an injected page. Successful exploitation requires comments to be open, a comment author name containinCVSS 6.1CVE-2026-136206 | The Export Products, Orders & Customers for WooCommerce plugin for WordPress is vulnerable to Reflected Cross-Site Scripting via the 'start_date' parameter in all versions up to, and including, 2.4.3 due to insufficient input sanitization and output escaping. This makes it possible for unauthenticated attackers to inject arbitrary web scripts in pages that execute if they can successfully trick a user into performing an action such as clicking on a link. SucCVSS 9.4CVE-2026-137706 | Smart Portal developed by Direk Tech has a Missing Authorization vulnerability. Authenticated remote attackers can add a specified account to the Active Directory Domain Admins group, thereby obtaining domain administrator privileges.CVSS 8.7CVE-2026-137705 | Smart Portal developed by Direk Tech has an Arbitrary File Read vulnerability.Unauthenticated remote attackers can exploit Relative Path Traversal to download arbitrary system files.
Alle im Drawer
Intelligence View
⚡ tsecurity.de Intelligence

# Understanding JavaScript Closures Through Call Stack, Heap Memory & `[[Scopes]]`

Closures aren't magic—they're simply JavaScript's way of keeping data alive when a function still needs it. Every JavaScript developer has heard statements l…

Beitrag
0
Seite
0
↗ Quelle (dev.to)
Quelle & Fakten · 4 Min. Lesezeit
Quelle: dev.to
Rubrik: Programación segura

Closures aren't magic—they're simply JavaScript's way of keeping data alive when a function still needs it.




Every JavaScript developer has heard statements like:




  • "A closure is a function that remembers variables from its outer scope."

  • "The inner function closes over variables."

  • "Closures preserve the lexical environment."



But...




  • How does a function actually remember variables?

  • Where are those variables stored after the outer function finishes?

  • Why doesn't JavaScript delete them?



Let's go beyond the textbook definition and see what actually happens inside the JavaScript engine.









The Two Main Players Inside the JavaScript Engine



Whenever a function executes, two important memory areas are involved:




  • Call Stack

  • Heap Memory



Understanding closures is really about understanding where JavaScript stores variables and why some of them survive after a function finishes executing.









1. What Happens in a Normal Function?



Consider a simple function:




function greet() {
let name = "JavaScript";
console.log(name);
}

greet();






When greet() executes:




  1. An Execution Context is created.

  2. Local variables (name) belong to that execution.

  3. The execution context is pushed onto the Call Stack.




Call Stack

┌─────────────────────────┐
│ Execution Context │
│ name = "JavaScript" │
└─────────────────────────┘






After the function finishes:




  • The execution context is popped off the stack.

  • No code references name anymore.

  • It becomes eligible for Garbage Collection.



Everything is cleaned up.









2. What Changes When a Closure Is Created?



Now look at this example:




function outerFunction() {

let count = 0;

function innerFunction() {
count++;
console.log(count);
}

return innerFunction;
}

const counter = outerFunction();

counter();
counter();
counter();






Output




1
2
3






But wait...



outerFunction() already finished executing.



Its execution context has been removed from the Call Stack.



So why is count still available?



That's where closures come in.









Behind the Scenes



When JavaScript notices that innerFunction uses count, it understands:




"This variable will still be needed after outerFunction() returns."




Instead of letting count disappear with the execution context, the engine keeps it alive.



Three important things happen behind the scenes.









Step A — Captured Variables Are Kept in Heap Memory



The variables that are captured by an inner function are stored inside an internal object called the Lexical Environment (often called the Closure Context).



Conceptually, you can think of it like this:




Heap Memory

Lexical Environment

{
count: 0
}






Unlike the Call Stack, heap memory isn't destroyed when the function returns.



This allows the captured variables to stay alive.




Note: Engines don't literally "move" variables from the stack to the heap. Instead, captured variables are stored in a heap-allocated lexical environment so they can outlive the function call.










Step B — The Secret Link ([[Scopes]])



Every function internally carries a hidden reference called:




[[Scopes]]






This hidden reference points to the lexical environment containing the variables it needs.



Conceptually:




counter
│
▼
[[Scopes]]
│
▼
Lexical Environment
{
count: 0
}






Even after outerFunction() has finished, the returned function still knows exactly where count lives.









Step C — The Scope Chain



Later, when you execute:




counter();






JavaScript performs variable lookup in this order:




  1. Check the function's local scope.

  2. If not found, follow [[Scopes]].

  3. Search the lexical environment.

  4. Continue upward until the variable is found.



This lookup process is called the Scope Chain.









Visualizing the Entire Process






Before outerFunction() Returns






Call Stack

┌────────────────────────────┐
│ outerFunction() │
│ count = 0 │
│ innerFunction() │
└────────────────────────────┘












After Returning






Call Stack

┌──────────────────────┐
│ Global Execution │
└──────────────────────┘


Heap Memory

┌────────────────────────┐
│ Lexical Environment │
│ count = 0 │
└────────────────────────┘

▲
│
[[Scopes]]
│
▼

innerFunction






The execution context is gone.



The variable survives because the returned function still references it.









A Simple Analogy



Imagine:





  • outerFunction() is a hotel room.


  • count is an important document.

  • Before checking out, you place the document in a secure locker (Heap Memory).

  • You hand the locker key ([[Scopes]]) to your child (innerFunction).



Even after the hotel room is empty, your child still has the key and can access the document whenever needed.



That's exactly how closures work.









Why Are Closures Useful?






1. Data Privacy



Closures let you create private variables.




function createCounter() {

let count = 0;

return {
increment() {
count++;
},

getCount() {
return count;
}
};
}






Nobody outside can directly modify count.









2. Maintaining State



Closures allow functions to remember information between calls.




const counter = outerFunction();

counter();
counter();
counter();






The value of count persists without using global variables.









Key Takeaways



✔ A closure is created when an inner function uses variables from its outer scope.



✔ JavaScript keeps those captured variables alive inside a heap-allocated lexical environment.



✔ The returned function stores a hidden reference called [[Scopes]] to that environment.



✔ As long as the function exists, the captured variables cannot be garbage collected.



✔ Variable lookup through these linked environments is called the Scope Chain.









Final Thought



Closures aren't magic.



They're simply the JavaScript engine preserving the variables that are still needed.



Once you understand the relationship between the Call Stack, Heap Memory, Lexical Environment, and the hidden [[Scopes]] reference, closures become one of the most elegant and powerful features of JavaScript.

Information ergänzen Fachhinweis, Update, Korrektur oder Quelle zur Meldung beitragen
Gäste-Hinweise werden kurz redaktionell geprüft und danach hier angezeigt.

Community-Hinweise zur Meldung

0 freigegeben
Social ReaktionenReagiere als Erste:r — dein Feedback zählt!
Informations-Bewertung:

💬 Debate de la comunidad y comentarios

🌐 Unirse al chat principal

Inicia el debate en el stream de difusión del Social Chat o envía arriba una contribución experta mediante el formulario de ampliación.

Valoración de la comunidad & prueba social
⭐ Valoración de los lectores
–
Ø / 5.0
Aún no hay valoraciones de lectores
¿Le ha resultado útil este artículo?
0
Dejar una valoración ahora
Valoración detallada (opcional)
Contenido & calidad
Fuente & credibilidad
Actualidad
Briefing de seguridad Gratis · baja en 1 clic

Intelligence Digest — gratis

Cada día las noticias de seguridad más importantes · baja en cualquier momento

Clústeres de historias relacionados & fuentes (IA vectorial)

6 Cluster
44 fuentes
Best Black Friday home office deals 2026 — save on our top-tested work essentials from Herman Miller, FlexiSpot, Logitech, Epson and more
Latest from TechRadar hace 19 min.
43 fuentes más
Latest from TechRadarhace 17 min.Sony WH-1000XM6 just hit a record-low price — now it's Black Friday Latest from TechRadarhace 12 min.Lenovo's Copilot+ IdeaPad Slim 3 with 16GB RAM and a 512GB SSD is £350 off for Black Friday The Vergehace 7 min.Our favorite headphones and earbuds are cheaper than ever ahead of Black Friday Computer Bildhace 21 min.Black Friday: Live-Show ab 16 Uhr – die besten Deals t3n.dehace 22 min.Black Friday: Alle guten Angebote zu Apple, Samsung, Fritz und Co. in der Übersicht Golem.dehace 13 min.Anzeige: Google Pixel 10a am Black Friday bei Amazon erstmals unter 380 Euro COMPUTER BILDhace 1 hCOMPUTER BILD: Die Deal-Checker! BLACK FRIDAY 2026 WIREDhace 32 min.The Best Black Friday Streaming Deals (2026): Apple TV, Disney, Paramount, and More GamingOnLinux Latest Articl…hace 39 min.itch.io Creator Day & Black Friday 2026 sale is live Latest from TechRadarhace 47 min.Best Black Friday MacBook Air deals: biggest discounts on Apple's thin and light laptop range Latest from TechRadarhace 37 min.Proton VPN vs ExpressVPN – which secure VPN should you pick this Black Friday? WIREDhace 9 hThe 108 Best Black Friday Deals Are Now Live: Our Expert Picks for 2026 WIREDhace 44 min.20 Best Black Friday Tech Deals (2026) WIREDhace 42 min.The 10 Best Black Friday TV Deals (2026): Save Up to 53% Off Giga.dehace 34 min.Black Friday 2026 bei Back Market: Dyson, Ninja und GoPro jetzt deutlich günstiger Cyber Security Newshace 1 hBlack Friday or Black Fraud Day? 7 Cyber Traps to Watch Out for Before You Click ‘Buy’ CNEThace 2 díasLive: Black Friday Is Here. Shop Our Favorite Deals and Save Up to 60% Apple, Anker, Bose and More WIREDhace 57 min.22 Best Black Friday Deals Under $100 (2026) WIREDhace 55 min.Best Black Friday Phone Deals (2026): iPhone, Pixel, and More The Vergehace 1 hThe absolute best Black Friday deals we’ve found (so far) Giga.dehace 54 min.AirPods Pro 3 im Black-Friday-Sturzflug: So günstig waren Apples Top-In-Ears noch nie PC-WELThace 52 min.Black Friday bei Amazon Haul: 20 Prozent Rabatt auf Powerbanks, Batterieprüfer, Speichersticks und mehr PC-WELThace 52 min.Black Friday bei Amazon Haul: 20 Prozent Rabatt auf Powerbanks, Batterieprüfer, Speichersticks und mehr t3n.dehace 1 hKindle, Echo Dot, Fire TV: Diese neuen Amazon-Geräte sind zum Black Friday stark reduziert Macerkopf.dehace 1 hAmazon Black Friday Woche: iPad Air, iPhone 18 Cases, AirTag 2, Fire TV Sticks, Echo Dot und mehr appgefahren.dehace 1 hJMGO mit Black Friday-Deals: Heimkino-Bundles bis zu 60 Prozent günstiger PC-WELThace 1 hGoogle Pixel 11 jetzt unglaubliche 430 Euro günstiger im Black-Friday-Deal: Tiefstpreis bei Amazon PC-WELThace 1 hNorton 360 Premium-Security an Black Friday nur 19,99 Euro statt 100 Euro Latest from TechRadarhace 1 hThe best Black Friday headphone deals: Sony, AirPods and more Latest from TechRadarhace 1 hBest Black Friday mini PC deals 2026 live: Save on desktops from Apple, Geekom, GMKtec, Minisforum, and more Golem.dehace 1 hAnzeige: Amazon startet mit Glücksrad-Gewinnspiel in den Black Friday Latest from TechRadarhace 1 hThese smart and polished backpacks have accompanied me to events all over the world — and they're now 30% for Black Friday PC-WELThace 1 hRiesiger 75 Zoll 4K-QLED-Fernseher fällt bei Amazon auf nur 469 Eur im Black-Friday-Angebot PC-WELThace 1 hBlack Friday: Beliebte Mähroboter von Mammotion jetzt ab 599 Euro Latest from TechRadarhace 1 hSave up to around £200 on these top mini PCs for Black Friday — with multiple options and configurations available for your exact needs or preferences Caschys Bloghace 3 hFlexiSpot Black Friday 2026: Bis zu 40 % Rabatt auf Bestseller bei Amazon Golem.dehace 1 hBlack Friday: Verdi mobilisiert bei Amazon in Gera nur wenige PC-WELThace 1 hNotebooksbilliger Black Friday: 150 Euro Extra-Rabatt – Laptops unter 300 Euro appgefahren.dehace 1 htink.de bietet bis zu 50 Euro Extra-Rabatt auf Black-Friday-Angebote PC-WELThace 1 hNotebooksbilliger Black Friday: 150 Euro Extra-Rabatt – Laptops unter 300 Euro Latest from TechRadarhace 2 hWhich all-in-one Black Friday VPN bundle is really worth it? I compared NordVPN Prime, ExpressVPN Pro, and Proton Unlimited — all under $7 a month — to decide PC-WELThace 2 hAmazon verlost an Black Friday Einkaufsgutscheine im Wert von 2.000 Euro PC-WELThace 2 hAmazon verlost an Black Friday Einkaufsgutscheine im Wert von 2.000 Euro
22 fuentes
CVE-2026-95457 | Google Android Camera reconnect.shard.cml privileges management
VulDB Updates hace 44 min.
21 fuentes más
VulDB Updateshace 44 min.CVE-2026-95458 | Google Android Bluetooth Setup bluetooth_setup_impl.cc OnAudioSourceConnectChanged privileges management VulDB Updateshace 44 min.CVE-2026-95464 | Google Android logical_link.cc SignalError use after free VulDB Updateshace 44 min.CVE-2026-95456 | Google Android a2dp_offload_manager.cc StartA2dpOffload use after free VulDB Updateshace 44 min.CVE-2026-95463 | Google Android data_element.cc DataElement::Read recursion Engadgethace 59 min.Google will soon share Android developers' addresses publicly VulDB Updateshace 1 hCVE-2026-95429 | Google Android BrEdrDynamicChannel bredr_dynamic_channel.cc resource consumption VulDB Updateshace 1 hCVE-2026-95434 | Google Android LowEnergyScanner low_energy_scanner.cc NotifyPeerFound resource consumption VulDB Updateshace 1 hCVE-2026-95441 | Google Android Bluetooth connection.cc OnDisconnectionComplete denial of service VulDB Updateshace 1 hCVE-2026-95422 | Google Android periodic_advertising_synchronizer.cc OnSyncEstablished assertion VulDB Updateshace 1 hCVE-2026-95423 | Google Android local_service_manager.cc OnWriteCCC null pointer dereference VulDB Updateshace 1 hCVE-2026-95447 | Google Android SDP Client client.cc OnRxFrame memory corruption VulDB Updateshace 1 hCVE-2026-95421 | Google Android Command Processing bredr_signaling_channel.cc DecodeRxUnit use after free VulDB Updateshace 1 hCVE-2026-95435 | Google Android advertising_data.cc FromBytes out-of-bounds VulDB Updateshace 1 hCVE-2026-95446 | Google Android credit_based_flow_control_rx_engine.cc ProcessPdu input validation VulDB Updateshace 1 hCVE-2026-95420 | Google Android Pairing security_manager.cc OnEncryptionChange privileges management VulDB Updateshace 1 hCVE-2026-95419 | Google Android Bluetooth Security Manager security_manager.cc OnPairingRequest unusual condition VulDB Updateshace 1 hCVE-2026-95416 | Google Android Link Encryption Key security_manager.cc OnPairingFailed denial of service VulDB Updateshace 1 hCVE-2026-95415 | Google Android RemoteCharacteristic remote_characteristic.cc denial of service VulDB Updateshace 1 hCVE-2026-95417 | Google Android remote_characteristic.cc ResolvePendingNotifyRequests use after free VulDB Updateshace 1 hCVE-2026-95414 | Google Android http_file_request_handler.cc GetFilePath path traversal VulDB Updateshace 1 hCVE-2026-95418 | Google Android logical_link.cc LogicalLink::SignalError use after free
Artículos similares
🔍 Verwandte News

Auch interessante Nachrichten # Understanding JavaScript Closures Through Call Stack, Heap Memory & `[[Scopes]]`

Thematisch verwandte Begriffe: Understanding, JavaScript, Closures, Through · 6 Treffer

Laden...

Cargando vídeos ...

Laden...

Cargando artículos ...

Laden...

Cargando vídeos ...

Laden...

Cargando artículos ...

Laden...

Cargando vídeos ...

Laden...

Cargando artículos ...

Laden...

Cargando vídeos ...

Laden...

Cargando artículos ...

Laden...

Cargando vídeos ...

💬 Cargando comentarios…
Desliza para actualizar
Widgets & Topics
Loading widgets…
Nächster Beitrag