Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
IT Security DownloadsGitHub Release: ollama/ollama v0.34.4-rc0 (23.09.2026)(23.09.2026 um 02:53 Uhr)
Sichere ProgrammierungMy fact-checker said CONFIRMED about a group that doesn't exist(23.09.2026 um 02:13 Uhr)
Sichere ProgrammierungZero-Friction Payment Architectures for Global Scalability(23.09.2026 um 02:20 Uhr)
IT Security DownloadsGitHub Release: ollama/ollama v0.34.4-rc0 (23.09.2026)(23.09.2026 um 02:53 Uhr)
Sichere ProgrammierungMy fact-checker said CONFIRMED about a group that doesn't exist(23.09.2026 um 02:13 Uhr)
Sichere ProgrammierungZero-Friction Payment Architectures for Global Scalability(23.09.2026 um 02:20 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Question of the Day #23 [Talk::Overflow]

Why parseInt(0.0000005) returns 5: The dangerous interaction between scientific notation and string coercion. This post explains a quiz originally shared as a LinkedIn poll. 🔹 The Question What will be the output / be…

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

Why parseInt(0.0000005) returns 5: The dangerous interaction between scientific notation and string coercion.



This post explains a quiz originally shared as a LinkedIn poll.









🔹 The Question



What will be the output / behavior?




const value = 0.0000005;
const result = parseInt(value);

console.log(result);






Hint: parseInt converts its first argument to a string before parsing. How does JavaScript represent very small numbers as strings?



Follow me for JavaScript puzzles and weekly curations of developer talks & insights at Talk::Overflow: https://talkoverflow.substack.com/









🔹 Solution



The correct output is 5.






🧠 How this works



This behavior is a classic example of implicit type coercion combined with scientific notation.




  1. Implicit String Conversion: The parseInt function expects its first argument to be a string. If you pass a number, JavaScript first converts it to a string using the abstract ToString operation.

  2. Scientific Notation: For very small numbers (specifically, those with more than 6 leading zeros after the decimal point), JavaScript's default string representation uses exponential notation.


    • String(0.000005) is "0.000005"

    • String(0.0000005) is "5e-7"



  3. Parsing Logic: parseInt parses the string from left to right. It stops parsing as soon as it encounters a character that is not a valid digit for the specified radix (default is 10).


    • It sees "5" (valid digit).

    • It sees "e" (invalid digit).

    • It stops and returns the integer parsed so far: 5.








🔍 Line-by-line explanation






const value = 0.0000005;
// value is stored as a number

const result = parseInt(value);
// Step 1: value is coerced to string -> "5e-7"
// Step 2: parseInt("5e-7") starts parsing
// Step 3: Parses '5', stops at 'e'
// Result: 5

console.log(result); // Output: 5












🔹 Key Takeaways




  • parseInt is for strings. Avoid using it on values that are already numbers.

  • Know your string representations. JavaScript automatically switches to scientific notation for numbers smaller than 1e-6.

  • Use Math methods for numbers. Math.trunc() is the safer, semantic equivalent for "drop the decimal part" on numeric values.

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Question of the Day #23 [Talk::Overflow]

Thematisch verwandte Begriffe: Question, TalkOverflow · 6 Treffer

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-17636 | IBM Financial Transaction Manager (FTM) for RedHat OpenShift could allow…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
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
🔖 Gespeicherte Artikel
📂 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 ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick