Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
IT Security NachrichtenOnePlus/OxygenOS: Schad-App erhält Root-Zugriff ohne Berechtigungen(24.09.2026 um 23:38 Uhr)
•
IT Security NachrichtenRyuk Member Karen Vardanyan Sentenced to Two Years in U.S. Prison(24.09.2026 um 22:50 Uhr)
•••••
Hacking & PentestingRyuk Member Karen Vardanyan Sentenced to Two Years in U.S. Prison(24.09.2026 um 22:50 Uhr)
•
AI & KI NachrichtenWhy the U.N. Still Matters(24.09.2026 um 23:00 Uhr)
•••
IT Security NachrichtenOnePlus/OxygenOS: Schad-App erhält Root-Zugriff ohne Berechtigungen(24.09.2026 um 23:38 Uhr)
•
IT Security NachrichtenRyuk Member Karen Vardanyan Sentenced to Two Years in U.S. Prison(24.09.2026 um 22:50 Uhr)
•••••
Hacking & PentestingRyuk Member Karen Vardanyan Sentenced to Two Years in U.S. Prison(24.09.2026 um 22:50 Uhr)
•
AI & KI NachrichtenWhy the U.N. Still Matters(24.09.2026 um 23:00 Uhr)
•••
Intelligence View
⚡ tsecurity.de Intelligence

finally() in JavaScript: Why It Can't (Usually) Change a Promise's Result

A common misconception is that finally() behaves like then(). In reality, it doesn’t receive values, ignores return values, and only affects a promise in very specific cases. Let’s see why. finally(): Why It Can’t Change a Promise …

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

A common misconception is that finally() behaves like then().


In reality, it doesn’t receive values, ignores return values, and only affects a promise in very specific cases. Let’s see why.





finally(): Why It Can’t Change a Promise Result





finally() doesn’t receive arguments



Let's start with a quick quiz to test your understanding:




myPromise.then(() => "Hi, Sasha!")
.finally(res => console.log(res + "Whats up?"))

//what will appear in console?






If you think the answer is “Hi, Sasha!Whats up?” then keep reading 🙂






How finally() works under the hood



The finally method doesn't have its own low-level implementation in the Promise specification.



Under the hood, it simply delegates to then, using the same callback for both success and failure:




promise.finally(onDone);
// is roughly equivalent to
promise.then(onDone, onDone);






Because of this onDone does not receive any arguments (no resolved value, no rejection reason)



And what happens to the parameter value which wasn’t passed? Correct: it stays undefined.



Correct answer to the quiz is “undefinedWhats up?“ as res value is undefined.






What happens to the Promise value after finally()?



Another quiz:




myPromise.then(() => "Hi, Sasha!")
.finally(res => "my new result")
.then(res => console.log(res)) //what will be logged here?






The answer is "Hi, Sasha!"



The value returned from finally() is simply ignored.



This is a key rule: finally() doesn’t change Promise’s state.



It exists for side effects only — cleanup logic, metrics, etc.






Why the returned value from finally() is ignored




  • finally() doesn’t receive the resolved value


  • it can’t pass a new value down the chain


  • the Promise continues with the value from the last then() or catch()




So this:




.finally(() => "new value")






is effectively the same as:




.finally(() => {})









Takeaways so far




  • Since finally() doesn't get any arguments, any value given to it stays undefined.


  • The return value from a finally() callback is ignored and doesn't change the Promise's state or the next then() chain


  • The Promise keeps the value from the last then() or catch() before finally() was called.







Can finally() change the Promise state?






Promise.resolve("OK")
.finally(() => {
throw new Error("Something went wrong");
})
.then((res) => console.log(res))
.catch((err) => console.log(err));

//what is the Promise state at this point?
//what will be logged? "OK" or "Something went wrong"?






At first glance, you might expect "OK".



After all, we already know that finally() doesn’t change a Promise’s value, right?



But in this case, the output will be “Something went wrong” and the Promise ends up rejected.






Why does this happen?



The important clarification is this:




finally() does not change a Promise’s state by default.




However, if an error is thrown inside finally() — or if it returns a rejected Promise — that error overrides the previous state.



Here is another quick quiz:




Promise.resolve("OK")
.finally(() => {
return Promise.reject("Something went wrong")
})
.then((res) => console.log(res))
.catch((err) => console.log(err));

//what is the Promise state at this point?
//what will be logged? "OK" or "Something went wrong"?






We are not throwing any error here. However, we are still getting the "Something went wrong" here.



Another way to change a Promise’s state is to return a rejected Promise from finally().



The takeaway we had previously is that the return value from a finally() callback is ignored, so why returning rejected Promise work?



Let’s investigate what happens under the hood.



Remember how finally() works?




promise.finally(onDone);
// is roughly equivalent to
promise.then(onDone, onDone);






Knowing that, let’s investigate our case:




Promise.resolve("OK")
.finally(() => {
return Promise.reject("Something went wrong")
})
.then((res) => console.log(res))
.catch((err) => console.log(err));

//is roughly the same as:


Promise.resolve("OK")
//this is our finally method
.then(

// first onDone callback
value => Promise.resolve(
(() => { return Promise.reject("Something went wrong"); })()
).then(() => value), // if resolves, continue with the previous value

// second onDone callback
reason => Promise.resolve(
(() => { return Promise.reject("Something went wrong"); })()
//throwing error
).then(() => { throw reason; }) // if gets rejected, continue with rejection reason as value
)
.then(res => console.log(res)) //this is ignored
.catch(err => console.log(err)); //this is called






Remember that throwing error changes Promise’s state?



This is what is done behind the scenes when we return a rejected Promise.



Note that if you return a new resolved promise from finally(), nothing changes. The chain waits for it to resolve, and then() continues with the original value.






Final takeaways




  • Since finally() doesn't receive any arguments, any value provided to it remains undefined.


  • The return value from a finally() callback is ignored and does not alter the Promise's state or affect the subsequent then() chain.



  • The Promise retains the value from the last then() or catch() before finally() was invoked, unless:




    • The method returns a rejected Promise.

    • An error is thrown within the method.






CTI Threat Relationship Graph2 Knoten / 1 Relationen
CVE / Incident Software MITRE ATT&CK CWE Weakness IoC
SOC Incident Playbook: Vulnerability Remediation & Verification
Syntax validiert (0 Fehler)
title: Detect Exploitation - finally() in JavaScript: Why It Can't (Usually) Change a Promise's Result
id: a6f8fbb0-6339-4627-bb08-529ec870d857
status: experimental
description: Automatisch generierte SIEM-Erkennungsregel basierend auf CTI Intelligence
references:
  - https://tsecurity.de/
author: iShareStuff CTI Automated Detection Engine
date: 2026-09-25
logsource:
  category: network_connection
  product: any
detection:
  selection:
      CommandLine|contains:
        - 'exploit'
  condition: selection
falsepositives:
  - Legitime administrative Zugriffe oder Penetrationstests
level: high
tags:
  - attack.initial_access
Syntax validiert (0 Fehler)
rule CTI_Threat_Indicator {
    meta:
        author = "iShareStuff CTI Automated Detection Engine"
        date = "2026-09-25"
        description = "YARA Signature for "
    strings:
        $str = "finally() in JavaScript: Why I" ascii wide
    condition:
        any of them
}
Syntax validiert (0 Fehler)
index=security sourcetype IN ("cisco:asa", "pan:traffic", "zeek_conn", "suricata", "WinEventLog:Security")
("finally in JavaScript Why It Cant Usuall")
| stats count earliest(_time) as first_seen latest(_time) as last_seen by src_ip, dest_ip, dest_host, signature
| eval first_seen=strftime(first_seen, "%Y-%m-%d %H:%M:%S"), last_seen=strftime(last_seen, "%Y-%m-%d %H:%M:%S")
| sort - count
Syntax validiert (0 Fehler)
message: "*finally in JavaScript Why It Cant Usuall*"
Syntax validiert (0 Fehler)
CommonSecurityLog
| where Message has "finally in JavaScript Why It Cant Usuall"
| summarize EventCount = count(), FirstSeen = min(TimeGenerated), LastSeen = max(TimeGenerated) by SourceIP, DestinationIP, DestinationPort, Activity
| extend DetectionRule = "iShareStuff-CTI-Compiled"
| sort by EventCount desc
🎯
MITRE ATT&CK Matrix Navigator 14 Taktiken
Reconnaissance
-
Resource Development
-
Initial Access
Execution
Persistence
-
Privilege Escalation
Defense Evasion
Credential Access
-
Discovery
-
Lateral Movement
-
Collection
-
Command and Control
Exfiltration
-
Impact
tsecurity.de Cognitive Threat RAG
Fokus-Vektor:

Kognitive Analyse für identifizierte Bedrohung: Erhöhte Bedrohungslage im Bereich finally() in JavaScript: Why It Can't (U.... Basierend auf 368k Vektor-Korrelationen werden sofortige Isolationsmaßnahmen für betroffene Endpunkte empfohlen.

🛡️ Angriffsfläche & Exposure

Netzwerk/Remote-Zugriff ohne Vorauthentifizierung möglich.

⚡ Empfohlene Sofortmaßnahmen
  • 1. Perimeter-Inspektion: Relevante Portfreigaben und exponierte Endpunkte unverzüglich scannen.
  • 2. Patch-Applikation: Hersteller-Hotfix einspielen oder betroffene Daemons in isolierte DMZ-Segmente überführen.
  • 3. Telemetrie & EDR-Alerts: Prozessaufrufe und Child-Processes auf anomale Shell-Spawns überwachen.
🔗 Semantisch verwandte Zero-Days MariaDB 11.7 VEC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten finally() in JavaScript: Why It Can't (Usually) Change a Promise's Result

Thematisch verwandte Begriffe: finally, JavaScript, Cant, Usually · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-81473 | Dell Rugged Control Center (RCC), versions prior to 5.2.206, contain an …
Advisory →
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel • Rechts: nächster Artikel • unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel TTP ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...
↗ Original-Quelle