TIL I learned that if you set the `length` property of a javascript array, it will truncate it. So bizarre.

```

a = [1,2,3]

a.length = 0

a === []

```

Reply to this note

Please Login to reply.

Discussion

You should also learn today Not to do „TIL I learned“ xD

Truly awful. It should be a read-only attribute or method.

That’s false, because === compares references, not contents. You’re comparing:

a → an existing (now empty) array object

[] → a brand new empty array object

Same contents, different identity.

you're right that it doesn't compare by value, but I was just trying to communicate that the array is indeed empty

I understand that is is used sometimes for performance because it doesn't allocate memory

I understand why you would want it, but a read-only property and a `clear` method would make way more sense. But it's javascript, you can't be too harsh

Yeah way more but I would never ask JavaScript for logic

javascript is so fun. i love these quirks.