1. 18
  1.  

  2. 4
    y = false, true; // returns true in console
    console.log(y); // false (left-most)
    

    Huh, that definitely tripped me up for a second. Is this because the comma is higher precedence than the assignment?

    1. 9

      The assignment to y belongs wholly to the expression on the left side of the comma operator: y = false. The left and right sides of the comma operator don’t interact. The comma operator is just a way to squeeze in two or more expressions where only one expression is valid, e.g. the first parameter of a for loop. The list of expressions is treated as a single expression that always evaluates to the result of the right-most expression. For that reason y = (false, true) has your expected result. Along the same lines var x = 1, y = 2 expands to var x; var y; x = 1; x = 2; because of variable hoisting.

    2. 2

      You can name for loops and blocks in JS… who knew (not me)!

      Babel Contracts leverages these to add simple function contracts to js code.

      1. 1

        This one I did know about. It’s the reason () => { pet: 'dog' } returns undefined instead of an object. The curlies are evaluated as enclosing the arrow function block and pet: is evaluated as a label for the expression 'dog' – so without an explicit return, the function returns undefined. If you intended, instead, to implicitly return an object with the property pet, the curlies should be wrapped in parens to denote an expression: () => ({ pet: 'dog' })

        It can also be used to send break to labeled recursive functions. Don’t know whether I like the idea. But it’s interesting.

      2. 1

        js is getting closer to a lisp like language

        1. 1

          given that it started as browser Scheme it’s spent a long time getting farther away from a lisp like language first 😭

        2. 1

          You can follow adoption of the pipeline operator here: https://github.com/tc39/proposal-pipeline-operator

          1. 1

            Atomics is neutered right now in Mozilla. Atomics use SharedArrayBuffer objects. But SharedArrayBuffer has been disabled for now as a mitigation for Spectre.