There have been multiple accounts created with the sole purpose of posting advertisement posts or replies containing unsolicited advertising.

Accounts which solely post advertisements, or persistently post them may be terminated.

programmer_humor

This magazine is from a federated server and may be incomplete. Browse more on the original instance.

drsensor , in Bug Fixing

My way: wrap it in a shell script and put a condition if exit status is not 0 then say “try clear the cache and run it again”

abraxas ,

AKA - the test suites at half the companies I’ve worked.

DrunkenPirate , in ===

ChatGpt: 1+1≈2

OpenStars ,
@OpenStars@startrek.website avatar

Reddit: 1+1=your muther (sic, x2)

X: 1+1≈we should violently overthrow the government

4chan: nvm, I don’t want to get banned for saying this one

Darkaga ,

4chan: "Gamer words"

OpenStars ,
@OpenStars@startrek.website avatar

No, that’s Discord 🙃

xedrak , in ===
@xedrak@kbin.social avatar

cries in PHP

xmunk ,

I also came to represent my php breathren.

tiredofsametab , in ===

1 + false ? (I have no idea in which order JS would evaluate things as I rarely have to touch that language much anymore)

Lucien , in ===

==== when

_edge ,

<span style="color:#323232;">==   same (after magic)
</span><span style="color:#323232;">===  same and same type (in Javascript)
</span><span style="color:#323232;">==== same and same type and same actual type (in the backend before conversion to JSON)
</span>
pocketman_stuck ,

Lolololol

pocketman_stuck ,

Lol

backhdlp , (edited ) in ===
@backhdlp@iusearchlinux.fyi avatar

I still don’t understand the === operator

Edit: I think a more type strict ==? Pretty sure I understand the point of typescript now.

SmoothIsFast ,

It’s like the ==, but there’s one more =

Limitless_screaming ,
@Limitless_screaming@kbin.social avatar

== but for JavaScript. What you don't understand is the == of JavaScript.

clb92 ,

Like == but more strict. The == operator will do type conversion, so 0 == ‘’ will actually be true, as an example. Sometimes (honestly, most times) you may want to compare more strictly.

See this StackOverflow answer: stackoverflow.com/…/which-equals-operator-vs-shou…

QuazarOmega ,

<span style="color:#323232;">> 1 == 1
</span><span style="color:#323232;">true
</span><span style="color:#323232;">> 1 == '1'
</span><span style="color:#323232;">true
</span><span style="color:#323232;">> 1 === '1'
</span><span style="color:#323232;">false
</span>

(from node REPL)

Basically it’s the real equals sign perfection

SzethFriendOfNimi ,

So in JavaScript there’s the assignment


<span style="color:#323232;">=
</span>

and the comparator is


<span style="color:#323232;">==
</span>

Since there’s no types JS will do implicit conversion before comparison when using == in a case like this


<span style="color:#323232;">if(false == '0'){
</span><span style="color:#323232;">    //this is true
</span><span style="color:#323232;">}
</span>

But with === it doesn’t. It means literally compare these


<span style="color:#323232;">if(false === '0'){
</span><span style="color:#323232;">    //this is false
</span><span style="color:#323232;">}else{
</span><span style="color:#323232;">    //so this will execute instead 
</span><span style="color:#323232;">}
</span>

But this, however, will


<span style="color:#323232;">var someState = false;
</span><span style="color:#323232;"> if(someState === false){
</span><span style="color:#323232;">    //this is true
</span><span style="color:#323232;">}
</span>
runswithjedi ,

deleted_by_author

  • Loading...
  • idunnololz ,
    @idunnololz@lemmy.world avatar

    Np. closed as duplicate

    kevincox ,
    @kevincox@lemmy.ml avatar

    JS’s == has some gotchas and you almost never want to use it. So === is what == should have been.

    All examples are true:

    
    <span style="color:#183691;">"1" </span><span style="font-weight:bold;color:#a71d5d;">== </span><span style="color:#0086b3;">true
    </span><span style="color:#323232;">[</span><span style="color:#0086b3;">1</span><span style="color:#323232;">, </span><span style="color:#0086b3;">2</span><span style="color:#323232;">] </span><span style="font-weight:bold;color:#a71d5d;">== </span><span style="color:#183691;">"1,2" 
    </span><span style="color:#183691;">" " </span><span style="font-weight:bold;color:#a71d5d;">== </span><span style="color:#0086b3;">false
    </span><span style="color:#0086b3;">null </span><span style="font-weight:bold;color:#a71d5d;">== </span><span style="color:#0086b3;">undefined 
    </span>
    

    It isn’t that insane. But some invariants that you may expect don’t hold.

    
    <span style="color:#183691;">"" </span><span style="font-weight:bold;color:#a71d5d;">== </span><span style="color:#0086b3;">0
    </span><span style="color:#183691;">"0" </span><span style="font-weight:bold;color:#a71d5d;">== </span><span style="color:#0086b3;">0
    </span><span style="color:#183691;">"" </span><span style="font-weight:bold;color:#a71d5d;">!= </span><span style="color:#183691;">"0" 
    </span>
    
    Feathercrown ,

    One neat feature is you can compare to both null and undefined at the same time, without other falsey values giving false positives. Although that’s not necessary as often now that we have nullish coalescing and optional chaining.

    kevincox ,
    @kevincox@lemmy.ml avatar

    I just tested and Terser will convert v === null || v === undefined to null==v. Personally I would prefer to read the code that explicitly shows that it is checking for both and let my minifier/optimizer worry about generating compact code.

    SzethFriendOfNimi ,

    Try changing to const === variable. That’s most likely what’s it doing to minimize the risk of accidental assignment.

    kevincox ,
    @kevincox@lemmy.ml avatar

    Wut? This is an automated optimizer. It is not worried about accidental assignment.

    SzethFriendOfNimi ,

    I agree it shouldn’t. But I’ve seen linters that automatically change it since they seem to be forcing practical conventions sometimes.

    kevincox ,
    @kevincox@lemmy.ml avatar

    Linters and minifers are completely different tools.

    SzethFriendOfNimi ,

    Good point. That’s what I get for shooting from the hip.

    Thanks!

    Bougie_Birdie ,
    @Bougie_Birdie@lemmy.blahaj.zone avatar

    The other comments explains it in pretty good detail, but when I was learning my teacher explained it sort of like a mnemonic.

    1 + 1 = 2 is read “one plus one equals two”

    1 + 1 == 2 is read “one plus one is equal to two”

    1 + 1 === 2 is read “one plus one is really equal to two”

    And you hit the nail on the head, is that === is type explicit while == is implicit.

    bobbykjack ,

    I’d use something like:

    = becomes == equals === is identical to

    It’s funny how everyone thinks “equals” in this context should be “identical to” when, in normal language, it doesn’t really mean that at all!

    frezik ,

    The short answer is that your language needs === when it fucked up the semantics of ==, but it’s also too popular and you can’t fix it without breaking half the web.

    marcos ,

    Or when it is something like Prolog, where equality is inherently a messy and complex concept.

    Mikina ,

    It’s also important if you’re checking hashes (at least, it was - if you’re using correct hashing algorithm that isn’t ancient, you will not have this problem).

    Because if you take for example “0e462097431906509019562988736854” (which is md5(“240610708”), but also applicable to most other hashing algorithms that hash to a hex string), if(“0e462097431906509019562988736854” == 0) is true. So any other data that hashes to any variantion of “0e[1-9]+” will pass the check, for example:

    md5(“240610708”) == md5(“hashcatqlffzszeRcrt”)

    that equals to

    “0e462097431906509019562988736854” == “0e242700999142460696437005736231”

    which thanks to scientific notation and no strict type checking can also mean

    0^462097431906509019562988736854^ == 0^242700999142460696437005736231^

    which is

    `0 == 0``

    I did use md5 as an example because the strings are pretty short, but it’s applicable to a whole lot of other hashes. And the problem is that if you use one of the strings that hash to a magic hash in a vulnerable site, it will pass the password check for any user who’s password also hashes to a magic hash. There’s not really a high chance of that happening, but there’s still a lot of hashes that do hash to it.

    darcy ,
    @darcy@sh.itjust.works avatar

    that is terrifying

    frezik ,

    If you’re checking passwords, you should be using constant time string checking, anyway.

    More likely, you should let your bcrypt library do it for you.

    ShortFuse ,

    You don’t need Typescript, you need an linter (eslint).

    === is your basic equality like all languages. == will implicitly cast type.

    The breakdown is here: 262.ecma-international.org/5.1/-11.9.3

    Modern JS says to never use == unless you’re comparing against null or undefined.

    luciole , in ===
    @luciole@beehaw.org avatar

    I wish the assignment operator wasn’t the equal sign.

    cerement ,
    @cerement@slrpnk.net avatar

    :=

    MxM111 ,

    That’s delayed assignment.

    cerement ,
    @cerement@slrpnk.net avatar

    procrastination assignment

    QuazarOmega ,
    
    <span style="color:#323232;">x 👈 5
    </span>
    
    xedrak ,
    @xedrak@kbin.social avatar

    Ok deal, but that means we need to change the equality operator to 👉👈

    OpenStars ,
    @OpenStars@startrek.website avatar

    You sonnofabitch I’m in!:-P

    OpenStars ,
    @OpenStars@startrek.website avatar
    
    <span style="color:#323232;">x 🔫 5
    </span>
    

    the pew pew principle /s

    Malgas ,

    Interpreter: Wait, x is 5?

    This code: Always has been.

    OpenStars ,
    @OpenStars@startrek.website avatar

    It is now, if you know what’s good for you.

    expr ,

    In Haskell, it’s the same as the mathematical = symbol.

    attero , in Bug Fixing

    The definition of insanity is doing the same thing over and over and expecting different results.

    BigBenis , in Bug Fixing

    The crazy thing is that sometimes this just works…

    aksdb , in Sleep() at home

    On microcontrollers that might be a valid approach.

    Darkassassin07 ,
    @Darkassassin07@lemmy.ca avatar

    But then I gotta buy a space heater too…

    YIj54yALOJxEsY20eU ,

    Microcontrollers run 100% of the time even while sleeping.

    towerful ,

    Nah, some MCUs have low power modes.
    ESP32 has 5 of them, from disabling fancy features, throttling the clock, even delegating to an ultra low power coprocessor, or just going to sleep until a pin wakes it up again. It can go from 240mA to 150uA and still process things, or sleep for only 5uA.

    YIj54yALOJxEsY20eU ,

    Nah, Sleeping != Low power mode. The now obsolete ATmega328 has a low power mode.

    kevincox ,
    @kevincox@lemmy.ml avatar

    I’ve written these cycle-perfect sleep loops before.

    It gets really complicated if you want to account for time spent in interrupt handlers.

    aksdb ,

    Thankfully I didn’t need high precision realtime. I just needed to wait a few seconds for serial comm.

    vcmj , in Sleep() at home
    drmoose , in Sleep() at home

    Javascript enters chat:

    
    <span style="color:#323232;">await new Promise(r => setTimeout(r, 2000));
    </span>
    

    Which is somehow even worse.

    KairuByte ,
    @KairuByte@lemmy.dbzer0.com avatar

    I mean, it’s certainly better than pre-2015.

    sbv ,

    As someone who likes to use the CPU, I don’t think it’s worse.

    tengkuizdihar , in Bug Fixing
    @tengkuizdihar@programming.dev avatar

    Einstein did say…

    Matty_r , in Sleep() at home
    @Matty_r@programming.dev avatar

    This should be the new isEven()/isOdd(). Calculate the speed of the CPU and use that to determine how long it might take to achieve a ‘sleep’ of a required time.

    henfredemars ,

    I took an embedded hardware class where specifically we were required to manually calculate our sleeps or use interrupts and timers rather than using a library function to do it for us.

    ExtraMedicated , in Sleep() at home

    I actually remember the teacher having us do this in high school. I tried it again a few years later and it didn’t really work anymore.

    snaggen ,
    @snaggen@programming.dev avatar

    On my first programming lesson, we were taught that 1 second sleep was for i = 1 to 1000 😀, computers was not that fast back then…

    aBundleOfFerrets ,

    I mean maybe in an early interpreted language like BASIC… even the Intel 8086 could count to 1000 in a fraction of a second

    snaggen ,
    @snaggen@programming.dev avatar

    This was in 1985, on a ABC80, a Swedish computer with a 3 MHz CPU. So, in theory it would be much faster, but I assume there were many performance losses (slow basic interpretor and thing like that) so that for loop got close enough to a second for us to use.

    en.m.wikipedia.org/wiki/ABC_80

  • All
  • Subscribed
  • Moderated
  • Favorites
  • [email protected]
  • random
  • lifeLocal
  • goranko
  • All magazines