Another Weird Looking JavaScript Operator?

Sdílet
Vložit
  • čas přidán 9. 07. 2024
  • The logical and assignment... &&= an ES 12 update in ECMAScript 2021 that looks bizarre but is another handy way to check for values before doing "x" operation. It checks to see if the thing on the left has a value (is truthy) and if so, overwrites it with the right! Click subscribe to keep on top of JavaScript Tuesday and I'll see you next time!
    ES Update Playlist: • EcmaScript Updates
    Code: github.com/robertbunch/es-next
    History of ECMAScript/JavaScript (long) - • Visual Timeline of Jav...
    History of ECMAScript/JavaScript (shorter) - • Visual Timeline of Jav...
    0:00 - Introduction
    0:59 - Example
    2:25 - Truthy
    2:46 -What it really does
    3:40 - Short-circuiting
    5:15 -Doc wrap-up
  • Věda a technologie

Komentáře • 1

  • @ahmad-murery
    @ahmad-murery Před 2 měsíci +1

    3:34 Sure enough it's 2 because you assigned it to 2 (you deleted the &&=2 while explaining how it works)😁
    Off topic I know, but we can have multiple expressions after the logical AND (&&).
    for example, here can assign values to both x and y if they both have no value (or falsy or any other condition that evaluates to true)
    let x, y
    !(x && y) && (x=1, y=2)
    Thanks Rob!