mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 23:28:02 +00:00
Add The Comma Operator as a javascript til
This commit is contained in:
@@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
|
|||||||
For a steady stream of TILs from a variety of rocketeers, checkout
|
For a steady stream of TILs from a variety of rocketeers, checkout
|
||||||
[til.hashrocket.com](https://til.hashrocket.com/).
|
[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)
|
- [Spread The Rest With ES6](javascript/spread-the-rest-with-es6.md)
|
||||||
- [String Interpolation With Template Literals](javascript/string-interpolation-with-template-literals.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)
|
- [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)
|
- [Throttling A Function Call](javascript/throttling-a-function-call.md)
|
||||||
- [Timing Processes](javascript/timing-processes.md)
|
- [Timing Processes](javascript/timing-processes.md)
|
||||||
- [Transforming ES6 and JSX With Babel 6](javascript/transforming-es6-and-jsx-with-babel-6.md)
|
- [Transforming ES6 and JSX With Babel 6](javascript/transforming-es6-and-jsx-with-babel-6.md)
|
||||||
|
|||||||
18
javascript/the-comma-operator.md
Normal file
18
javascript/the-comma-operator.md
Normal file
@@ -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`.
|
||||||
Reference in New Issue
Block a user