5 ms·
Assignment within the brackets, that kinda surprised me > a = [] > a[a[typeof a]='huh', void a] = 'puh' > console.log(a) [object: "huh", undefined: "p
by jhaglund 13y ago
Assignment within the brackets, that kinda surprised me
> a = []
> a[a[typeof a]='huh', void a] = 'puh'
> console.log(a)
[object: "huh", undefined: "puh"]
huh... you can do this too
> a = []
> a[a[a[typeof a]='huh'] = 'puh'] = 'woh'
> console.log(a)
[object: "huh", huh: "puh", puh: "woh"]
- Tloewald 13y agoThe comma operator in Javascript is a major WTF. The entire post basically comes down to a, b evaluates to b, [] coerces to string, and arrays are objects. The only thing to really look bad is chrome, which is surprisingly easy to kill.
- shinuza 13y ago> a.length 0 Same as the article, you are adding properties to a. A is an array, not an hashmap. Any index that is not a number will create a property, not a new index.