top | item 5867451

(no title)

jhaglund | 12 years 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"]

discuss

order

Tloewald|12 years ago

The 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|12 years 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.