As gdoron noted,
var a = "a"; var b = "b"; a = [b][b = a,0];
A and b will change, and although it looks a bit hacky, it has aroused my curiosity, and I am very curious how this works. That makes no sense to me.
b
var a = "a"; var b = "b"; a = [b][b = a, 0];
Let me break the last line into pieces:
[b] // Puts b in an array - a safe place for the swap. [b = a] // Assign a in b [b = a,0] // Assign a in b and return the later expression - 0 with the comma operator.
so finally, this is a =[b][0] - the first object in the array [b] => b assigned to a
a =[b][0]
[b]
a
Live demo
read @am not I comment on this question:When is the comma operator useful?This is his code ...
This can help (or prevent) thinking about these terms from a semantically equivalent lambda construct (here, parameter c replaces element 0):
c
a = (function(c) { b = a; return c; })(b);
Source: https://habr.com/ru/post/911620/More articles:System.MissingMethodException: there is no constructor without parameters for the object. - asp.net-mvcJavaScript code for a Math object - javascriptChrome extension - change right-click browser action menu - javascriptUsing a character before defining it - haskellPlay / Pause HTML5 Video Using JQuery - jqueryhttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/911621/whats-a-better-way-to-swap-two-argument-values&usg=ALkJrhjH_cfGpk-JkxEE63v3BK4jV93YqQhttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/911622/is-it-okay-to-use-with&usg=ALkJrhiVgA2Z3WZSojvb05HWFLk2nLpYvwHeader, footer and large tables with iTextSharp - asp.netIn-place autocomplete editor - jqueryUsing itertools.product and want to align the value - pythonAll Articles