diff --git a/README.md b/README.md index d27e2ef..694bebe 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/). For a steady stream of TILs from a variety of rocketeers, checkout [til.hashrocket.com](https://til.hashrocket.com/). -_736 TILs and counting..._ +_737 TILs and counting..._ --- @@ -279,6 +279,7 @@ _736 TILs and counting..._ - [Spread The Rest With ES6](javascript/spread-the-rest-with-es6.md) - [String Interpolation With Template Literals](javascript/string-interpolation-with-template-literals.md) - [Test Coverage Stats With Jest](javascript/test-coverage-stats-with-jest.md) +- [The Comma Operator](javascript/the-comma-operator.md) - [Throttling A Function Call](javascript/throttling-a-function-call.md) - [Timing Processes](javascript/timing-processes.md) - [Transforming ES6 and JSX With Babel 6](javascript/transforming-es6-and-jsx-with-babel-6.md) diff --git a/javascript/the-comma-operator.md b/javascript/the-comma-operator.md new file mode 100644 index 0000000..42f9044 --- /dev/null +++ b/javascript/the-comma-operator.md @@ -0,0 +1,18 @@ +# The Comma Operator + +I was surprised to see the result of this line of code: + +```javascript +const what = (1,2,3,4); +console.log(what); //=> 4 +``` + +I asked around on +[twitter](https://twitter.com/jbrancha/status/1084936559323951105) and +learned that the syntax construct at play here is the [comma +operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator). + +> The comma operator evaluates each of its operands (from left to right) and +> returns the value of the last operand. + +And that is why `what` gets bound to `4`.