Logical operators && TRICKS with short-circuit evaluation - Beau teaches JavaScript

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 ม.ค. 2025

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

  • @vitaliypogoretsky3199
    @vitaliypogoretsky3199 6 ปีที่แล้ว +60

    || stops on "truth", && stops on "lie". Remember :)

  • @MarcoAntonio-fh7rd
    @MarcoAntonio-fh7rd 7 ปีที่แล้ว +7

    I was searching for the last explanation, thanks Beau, great tutorial

  • @keifer7813
    @keifer7813 2 ปีที่แล้ว +1

    4:49 How can you call a function with no arguments when the function declaration has a parameter?

    • @shilpas5441
      @shilpas5441 2 ปีที่แล้ว +2

      Apparently the browser assigns the parameter with 'undefined'. So the function call is still valid.

  • @bruhmoment3731
    @bruhmoment3731 3 ปีที่แล้ว +2

    Thank you!

  • @shaikhzoyeb
    @shaikhzoyeb 6 ปีที่แล้ว +3

    thanks that's helpful

    • @muthimuthi5087
      @muthimuthi5087 4 ปีที่แล้ว

      S qx!x fastest-growing yyxyyyyy try 6dyes ytx city 6dyes d try zzz dyxyxyyxyyxy Urdu and dydydy strategy dyes Rudy x US ydy sags y u uddx 6dye, xyxyxyxxy66xd x dxxdd b h ddxuxuddx hybrid fu d 7dzd h 877xu87xu7877xu87xu7yxyxmmmmmmmmmmm0?+ mhmm mmyxyx TRY RUDY

  • @Moist_yet_Crispy
    @Moist_yet_Crispy 6 ปีที่แล้ว +2

    Great video! Thanks for this!

  • @fwostedfwakes733
    @fwostedfwakes733 4 ปีที่แล้ว

    I'm confused at the 3:40 example. Shouldn't !test run isTrue() instead of isFalse() because !test is actually true?

    • @heyman3731
      @heyman3731 4 ปีที่แล้ว +2

      i hope you have found the solutions or it . but for anyone wondering or confused about that part of code :.
      if (!test) : means that if test is not true . this is the condition we gave to to js . beau changed the value of test to FALSE . Which resulted in javascript checking if the test is not equal to True , which eventually turn out to be right thats why the block code was executed .

  • @aybak3k
    @aybak3k 2 ปีที่แล้ว

    cam here to learn it
    figured out
    i do it all the time in bash 😆

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

    thank you very match

  • @SogMosee
    @SogMosee 7 ปีที่แล้ว

    Is it possible to use short-circuit evaluation with multiple variables? I would think so, but for some reason, this fails:
    let amountLength = transactionAmountField.value.length === 0,
    methodLength = methodSelect.value.length === 0,
    categoryLength = categorySelect.value.length === 0,
    disable = () => transactionSubmitButton.disabled = true,
    activate = () => transactionSubmitButton.disabled = false
    (amountLength || methodLength) && disable()
    The disable function is not called despite both amountLength and methodLength being equal to 0.

    • @SogMosee
      @SogMosee 7 ปีที่แล้ว +1

      Nevermind, I figured it out! Here is the correct code:
      !!(amountLength || methodLength) && disable()
      !!(!amountLength && !methodLength) && activate()
      The first variable merely needed to be converted into a boolean.

    • @andrewmiddleton2308
      @andrewmiddleton2308 2 ปีที่แล้ว

      @@SogMosee What`s the !! for?

  • @momakplayz7985
    @momakplayz7985 3 ปีที่แล้ว

    What about "!" statement?

    • @stomperhk9107
      @stomperhk9107 3 ปีที่แล้ว

      It reverses the value.
      E.g:
      !true // false
      !false // true
      !0 // true

  • @christianrodier3381
    @christianrodier3381 6 ปีที่แล้ว +1

    That was very helpful thanks

  • @CarlosEstebanLopezJaramillo
    @CarlosEstebanLopezJaramillo 7 ปีที่แล้ว

    You know what's lacking? to explain the caution when using short circuit evaluation when assigning a boolean, what if you expect a boolean but you just want to avoid having null or undefined?

    • @stomperhk9107
      @stomperhk9107 3 ปีที่แล้ว

      Use the double not (!!) operator or the double question mark (??) operator, I didn't undestand wgat you tried to say.

    • @CarlosEstebanLopezJaramillo
      @CarlosEstebanLopezJaramillo 3 ปีที่แล้ว +1

      @@stomperhk9107 Can't remember what I was going for, probably exactly that (??) operator, which I think did not exist or was not yet implemented 4 years ago when I made the comment.

    • @stomperhk9107
      @stomperhk9107 3 ปีที่แล้ว +1

      @@CarlosEstebanLopezJaramillo Uhum, I see. I think that it didn't existed 4 years ago either.

    • @CarlosEstebanLopezJaramillo
      @CarlosEstebanLopezJaramillo 3 ปีที่แล้ว

      @@wplaunchers Don't have a reason to change it.

    • @keifer7813
      @keifer7813 2 ปีที่แล้ว

      @@CarlosEstebanLopezJaramillo I wouldn't remember either after 5 years haha

  • @busyrand
    @busyrand 2 ปีที่แล้ว +1

    React sent me....

  • @eugenenovikov671
    @eugenenovikov671 4 ปีที่แล้ว

    function(name) { name = name } - are u serious?????????????????????

  • @GretSeat
    @GretSeat 2 ปีที่แล้ว

    I'm even more confused now.

  • @marianenkoulas4953
    @marianenkoulas4953 ปีที่แล้ว +1

    Gbvgg

  • @emilybrock3822
    @emilybrock3822 ปีที่แล้ว

    Yife

  • @elhadiziat764
    @elhadiziat764 ปีที่แล้ว

    very confusing explanation with very quick code writing!

  • @roguehoe
    @roguehoe 3 ปีที่แล้ว

    Uh