1013
JavaScript (lemmy.ml)
(page 2) 50 comments
sorted by: hot top controversial new old
[-] Supervisor194@lemmy.world 7 points 6 months ago* (last edited 6 months ago)

It's not that hard to understand what it is doing and why the decision was made to make it do that. JavaScript has a particular purpose and it's mission is not consistency.

It's not like TypeScript doesn't exist if you just get lightheaded at the idea of learning JavaScript's quirks and mastering using it despite them.

load more comments (9 replies)
[-] sirico@feddit.uk 5 points 6 months ago

Oh we've hit an issue that's solved by another language or we could make another framework

[-] kamen@lemmy.world 5 points 6 months ago

If you're consciously and intentionally using JavaScript like that, I don't want to be friends with you.

[-] bitjunkie@lemmy.world 4 points 6 months ago* (last edited 6 months ago)

It's because + is two different operators and overloads based on the type to the left, while - is only a numeric operator and coerces left and right operands to numeric. But frankly if you're still using + for math or string concatenation in 2025, you're doing it wrong.

[-] Hadriscus@lemm.ee 8 points 6 months ago

I know nothing about javascript, what is wrong with using + for math? perhaps naively, I'd say it looks suited for the job

[-] Quibblekrust@thelemmy.club 6 points 6 months ago

It's much better to make your own function that uses bitwise operations to do addition.

function add(a, b) {
    while (b !== 0) {
        // Calculate carry
        let carry = a & b;

        // Sum without carry
        a = a ^ b;

        // Shift carry to the left
        b = carry << 1;
    }
    return a;
}

(For certain definitions of better.)

load more comments (3 replies)
load more comments
view more: ‹ prev next ›
this post was submitted on 04 Jun 2025
1013 points (100.0% liked)

Programmer Humor

27690 readers
315 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS