!! &&

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 ก.ย. 2024

ความคิดเห็น • 100

  • @TeHzoAr
    @TeHzoAr 9 หลายเดือนก่อน +224

    Only a JavaScript Dev could try to reinvent the if statement and have it be this obtuse

    • @robertsandiford6223
      @robertsandiford6223 8 หลายเดือนก่อน +12

      You're mistaken. This is part of an "expression", not a "statement" meaning that "if" cannot be used here.

    • @sourtil7158
      @sourtil7158 8 หลายเดือนก่อน +5

      You cannot use if in a jsx expression.

    • @Smbrine
      @Smbrine 8 หลายเดือนก่อน

      @@sourtil7158lol what? Ok there are ternaries instead which are way more readable than bang-bang

    • @sakithb
      @sakithb 7 หลายเดือนก่อน

      @@robertsandiford6223you can use a ternary

    • @chill89892
      @chill89892 7 หลายเดือนก่อน

      @@robertsandiford6223 but doing "playlists.length !== 0"" is essentially an if

  • @nithinsvarrier670
    @nithinsvarrier670 8 หลายเดือนก่อน +81

    Just make the expression,
    playlist.length > 0 && statemnt

    • @0ninetyseven97
      @0ninetyseven97 7 หลายเดือนก่อน

      && before should work too

    • @SkyyySi
      @SkyyySi 7 หลายเดือนก่อน +9

      That one's the best. It reads exactly like what you want to actually do.

    • @essana3
      @essana3 7 หลายเดือนก่อน +2

      anyone who writes array.length && is a lazy and bad developer

    • @chill89892
      @chill89892 7 หลายเดือนก่อน +4

      ​@@essana3How else would you achieve this ?

    • @essana3
      @essana3 7 หลายเดือนก่อน

      @@chill89892it's a condition so devs should stop being lazy and provide and readable boolean. array.length > 0 ALWAYS.

  • @stevecarter8810
    @stevecarter8810 7 หลายเดือนก่อน +9

    So glad you added that last line. Whenever i get to mentor programmers it's a big challenge to get them to let go of cute forms that make them look smart. It's hard on the ego to write code that looks as simple as it actually is.

  • @Lord_zeel
    @Lord_zeel 7 หลายเดือนก่อน +6

    I was like "wow, that's dumb" until the very end, then I was laughing uncontrollably. Well played.

    • @thierryvt
      @thierryvt 7 หลายเดือนก่อน

      had us in the first half not gonna lie lmao.

  • @mskzzz
    @mskzzz 8 หลายเดือนก่อน +19

    The solution is to write > 0 at the end. It's easier to read and more obvious.

    • @keitsee
      @keitsee 7 หลายเดือนก่อน +1

      You missed the punchline.

    • @CZghost
      @CZghost 7 หลายเดือนก่อน

      @@keitsee I can see the importance of it, but given it is a stupid ass punchline, I elected to ignore it.

  • @jimbrannlund4677
    @jimbrannlund4677 8 หลายเดือนก่อน +18

    Love the last statement! 😂

  • @DanielNit
    @DanielNit 8 หลายเดือนก่อน +3

    Tbh it's far too common to use !!x && ... In JS frontends to be "hard to understand" by anyone with at least a few months of experience.

  • @jack_mc8
    @jack_mc8 7 หลายเดือนก่อน

    After words “Lines… don’t work correctly”, I decided to pause and think what’s wrong, in a few seconds, I thought there is no handler for undefined and null values, so we need to add !! at the beginning. What a pleasant feeling to be right 😅

  • @michaelevans9392
    @michaelevans9392 7 หลายเดือนก่อน

    that last bit got me. I pretty much stopped using this syntax because it's just harder to understand. I strive for simplicity wherever I can nowadays.

  • @Mathhead2000
    @Mathhead2000 6 หลายเดือนก่อน

    In my mind !! is the connonical way to cast to Boolean, and unary + is the connonical way to cast to Number. It's just easier to write, and not hard to read imo. More languages need a !! operator.

  • @manjunathag7072
    @manjunathag7072 หลายเดือนก่อน

    Awesome

  • @_anlim309
    @_anlim309 6 หลายเดือนก่อน

    Not gonna lie, you got me on the first half.

  • @dvillegaspro
    @dvillegaspro 7 หลายเดือนก่อน

    The actual solution is to follow the react docs which say you should always use a ternary like `array.length ? : null` instead of using && precisely because of this issue

  • @FzsHotDogInDonut
    @FzsHotDogInDonut 9 หลายเดือนก่อน +6

    i love this humor

  • @sanusihassan7125
    @sanusihassan7125 3 หลายเดือนก่อน

    ternary operator left the room

  • @Darkpill-2
    @Darkpill-2 6 หลายเดือนก่อน

    This is why JavaScript is only considered a scripting language and not a real programming language.

  • @tszkinwong6170
    @tszkinwong6170 19 วันที่ผ่านมา

    Thank you subscribed!

  • @jackdra
    @jackdra 8 หลายเดือนก่อน +7

    Explicit is better than implicit

    • @Fubbel42
      @Fubbel42 8 หลายเดือนก่อน

      Not in JavaScript it ain't

  • @danielmajer1648
    @danielmajer1648 9 หลายเดือนก่อน +18

    Isn't it easier to use {expression? Element : null} ? And not using weird sh*t just because it exists?

    • @fullfungo
      @fullfungo 8 หลายเดือนก่อน +2

      Even better {expr? JSX: }.

    • @nithinsvarrier670
      @nithinsvarrier670 8 หลายเดือนก่อน +2

      The && is not the problem here. Rather .length returns a number instead of a boolean

    • @Qbe_Root
      @Qbe_Root 8 หลายเดือนก่อน

      ​@@nithinsvarrier670 What's the problem with .length returning a number?

    • @sohigh7433
      @sohigh7433 8 หลายเดือนก่อน

      ​@@Qbe_Rootthe guy in the video explained it. If it's a numerical value, it will be displayed. If it's null, undefined, or true/false (boolean) it won't.

    • @rkidy
      @rkidy 8 หลายเดือนก่อน

      @@Qbe_Rootyou commented on the short, so you must have watched it, and that’s the only thing he talks about. So I don’t understand how you missed the only thing he said.

  • @infiniteplanes5775
    @infiniteplanes5775 7 หลายเดือนก่อน +1

    Finally someone gets it!

  • @Nellak2011
    @Nellak2011 7 หลายเดือนก่อน

    2 potential reading properties of undefined errors from playlists.length and entities.length. Replace with ? instead.
    Now if playlists or entities is:
    0, null, undefined, NaN, or false it will not display the components, otherwise it will.
    So assuming we have a playlists and entities of the proper type that has a .length method, it should only be false when its length is 0, true otherwise.
    Also, ensure that you want to potentially display both components at once, because they can both display.

  • @shubhambhattacharjee1111
    @shubhambhattacharjee1111 8 หลายเดือนก่อน

    I always prefer !== than !!, even if it's concise, I think in this case the explicit version is better.

  • @sosquite8866
    @sosquite8866 7 หลายเดือนก่อน

    I was going to criticize and then i heard the last statement and immediately agreed, nice vid bro

  • @cocolasticot9027
    @cocolasticot9027 7 หลายเดือนก่อน

    If we make it opaque enough, we will achieve total domination over the web. Probably.

  • @pxkqd
    @pxkqd 7 หลายเดือนก่อน

    Tbh it's a pretty common trick, nothing weird about it.

  • @bloodylupin
    @bloodylupin 7 หลายเดือนก่อน

    you can use
    variablename ? : null
    and no problems

  • @user-oo4ev3en5r
    @user-oo4ev3en5r 7 หลายเดือนก่อน

    I love your taste of humour 😂

  • @darkhorse99900
    @darkhorse99900 8 หลายเดือนก่อน

    Does anyone else like explicitly writing Boolean() instead of !! I think it’s more clear…? Any thoughts?

  • @crashdavis4123
    @crashdavis4123 6 หลายเดือนก่อน

    lol I love it

  • @gabrielbianchi2246
    @gabrielbianchi2246 8 หลายเดือนก่อน

    My dude please continue making videos. There’s something different about how you explain, that just makes me think:
    Dang this guy will make some views in the long run

  • @danielroden9424
    @danielroden9424 7 หลายเดือนก่อน

    yes and he didnt leave a comment on the line above. job security!

  • @sg-ck2oh
    @sg-ck2oh 9 หลายเดือนก่อน +4

    Yea saw this in work did not understand then, now it's different thanks !!!!

    • @orterves
      @orterves 8 หลายเดือนก่อน

      You only need !! Btw !!!! Is redundant (but if you told me it was necessary in some scenario in JS, I'd believe you)

  • @handmadesoap8327
    @handmadesoap8327 9 หลายเดือนก่อน

    Or maybe you put code to render another page with cute image and text to recommend to upload the playlist if the legth is 0 on the very top so that code will be slightly become simple and can provide better ui/ux

  • @pranjalmantri5105
    @pranjalmantri5105 7 หลายเดือนก่อน

    Can't we use the Nullish Coalescent Operator here?

  • @fullstack_journey
    @fullstack_journey 7 หลายเดือนก่อน

    F*** JAVASCRIPT!!!
    - Jim on a Tuesday afternoon

  • @D0CTOR-ZED
    @D0CTOR-ZED 7 หลายเดือนก่อน

    You worked hard to make that code. Why shouldn't future you work just as hard to understand it.

  • @marvin674
    @marvin674 7 หลายเดือนก่อน

    Nulish coalescing?

  • @meertarbani1643
    @meertarbani1643 8 หลายเดือนก่อน +2

    (playlists.length > 0) is crying in the corner

  • @x911
    @x911 7 หลายเดือนก่อน

    This isn’t the correct solution, the correct solution is: { conditional_statement ? true : null }

  • @bravethomasyt
    @bravethomasyt 7 หลายเดือนก่อน

    Obligatory "this wouldn't happen in Vue".

  • @jamaka_me_code796
    @jamaka_me_code796 8 หลายเดือนก่อน

    Nice

  • @yogeshvanzara5553
    @yogeshvanzara5553 8 หลายเดือนก่อน

    I would rather say don't be smart make code readble..

  • @chris52000
    @chris52000 8 หลายเดือนก่อน

    This is why people hate on React, because people use short circuiting and ternaries instead of if statements or a function like normal people

    • @XDBjoernXD
      @XDBjoernXD 8 หลายเดือนก่อน

      For me I try to archive all the logic before the return, so my JSX look more concise. Make it more readable to me.

  • @0xtz_
    @0xtz_ 9 หลายเดือนก่อน

    using the eslint coming with the next.js keep yelling to not do this hhh idk why 😂 some other configs give the error too

  • @ThatGuy68580
    @ThatGuy68580 7 หลายเดือนก่อน

    Java vs Javascript

  • @adrianbunea2006
    @adrianbunea2006 8 หลายเดือนก่อน

    I like this but Eslint doesn't like it

  • @loydcose2780
    @loydcose2780 7 หลายเดือนก่อน

    Or you can use ??

  • @satishthapa1686
    @satishthapa1686 8 หลายเดือนก่อน

    5 sec before i got the 0 in my frontend wtf😂

  • @PostMeridianLyf
    @PostMeridianLyf 7 หลายเดือนก่อน

    playlist && playlist.length ()...

  • @deldrinov
    @deldrinov 7 หลายเดือนก่อน

    WTF that looks disgusting!
    *last sentence*
    I now remember why I hate webdev so much

  • @KimberlyWilliamsch
    @KimberlyWilliamsch 7 หลายเดือนก่อน

    I don't get it 😢

  • @emmanikenna
    @emmanikenna 6 หลายเดือนก่อน

    No. It doesn't make you smarter.

  • @matrioxplayz1607
    @matrioxplayz1607 8 หลายเดือนก่อน

    who doesn't use terniary operators here????

  • @SquaredbyX
    @SquaredbyX 8 หลายเดือนก่อน

    I don't disagree

  • @zir1010011010
    @zir1010011010 8 หลายเดือนก่อน

    imo more readable would be to just go `playlists.length > 0`, expresses what you mean more

  • @axeor1166
    @axeor1166 8 หลายเดือนก่อน +2

    Why would a logical AND operator return a div? JS is getting ridiculous 😩

    • @SamMeechWard
      @SamMeechWard  8 หลายเดือนก่อน +2

      Logical and returns the last truthy value or the first falsy value

    • @zir1010011010
      @zir1010011010 8 หลายเดือนก่อน +2

      it's called a short circuit of logical operators, has nothing to do with js

  • @daniel4dev
    @daniel4dev 7 หลายเดือนก่อน

    Or...... Use a better framework other than React

  • @VincentDECAUX
    @VincentDECAUX 8 หลายเดือนก่อน

    Why did he suicide ?
    "He was making a code review of JS code"

  • @j.r.r.tolkien8724
    @j.r.r.tolkien8724 8 หลายเดือนก่อน

    Theme please..

  • @guilhermeborges4228
    @guilhermeborges4228 9 หลายเดือนก่อน +1

    The developers that don't know this are justing showing their lack of knowledge. I don't think this code is obtuse.

  • @ruinenlust_
    @ruinenlust_ 7 หลายเดือนก่อน

    Because you should just use an if statement like a normal person

  • @prawnydagrate
    @prawnydagrate 8 หลายเดือนก่อน

    svelte > react

  • @willd4686
    @willd4686 7 หลายเดือนก่อน

    I fucking hate that JSX has lead to this god awful style of conditional rendering.

  • @user-re8lt2gy3g
    @user-re8lt2gy3g 8 หลายเดือนก่อน

    Fuzk react !

  • @aat01
    @aat01 8 หลายเดือนก่อน

    I prefer ternary. (? and : ) its clear and concise. Yet !! is cool 😎

  • @mooncorizer290
    @mooncorizer290 7 หลายเดือนก่อน

    playlists.length ? : nothing found

  • @torvic99
    @torvic99 7 หลายเดือนก่อน

    playlists.length > 0

  • @prawnydagrate
    @prawnydagrate 8 หลายเดือนก่อน

    svelte > react