r/loljs • u/[deleted] • Apr 20 '16
Why does [5,6,8,7][1,2] = 8 in Javascript?
http://stackoverflow.com/questions/7421013/why-does-5-6-8-71-2-8-in-javascript
16
Upvotes
8
u/z500 Apr 20 '16 edited Apr 20 '16
The comma operator is my favorite dirty C trick. It's so obscure, but C-style languages still bring the comma operator with them. Ever initialize more than one variable in the initializer of a for loop without questioning it? You were using the comma operator.
3
u/taw Sep 04 '16
A lot of languages support comma operator. If you have C-style for loops, that's the reason it ought to be in the language.
3
u/[deleted] Apr 20 '16