I've been looking for an answer to my question, but so far I haven't had any luck finding it through search engines. It seems like using the plus sign '+' in a search query is not very effective with Google or Bing.
Nevertheless, why does this result in zero?
+[[]][0] // = 0
while this results in one?
++[[]][0] // = 1
UPDATE: Michael Berkowski provided a good explanation, but there's still one part that confuses me.
If [[]][0]
evaluates to an empty array, then why does ++[]
yield a
ReferenceError: Invalid left-hand side expression in prefix operation
?
UPDATE 2: I think I understand now...it seems like I was mistakenly trying to type ++0 in the console and getting an error, when actually I should be using var a = 0; ++a.