+ 4

JavaScript Garbage Collector

Here's a somewhat difficult question. Let's say I declare an array as follows: var arr = [1, 2, 3]; and I set the length of the array to 2 as follows: arr.length = 2; Would the garbage collector remove the third element from memory? Does anyone know the answer?

7th Feb 2019, 9:05 PM
Division by Zero
2 Answers
+ 6
Yes it will. arr will then be [1, 2]. You can test it in the Code Playground.
7th Feb 2019, 9:17 PM
Rowsej
Rowsej - avatar