I have a fairly large array in a node.js script I am writing that exists in the program's memory for only about a couple of seconds. The array stores metadata for some other (irrelevant) array in string format for about 6,000-7,000 items and when it is processed it is cleared from memory.
When a value in this array doesn't require any metadata I simply set the value to an empty string ''
. However, I've recently been looking at changing the data type to undefined
to save memory (there are 6k items in this array, after all.)
Are there any pros/cons for using an empty string vs. undefined
in the realm of program optimization? Is it such a small difference that it doesn't even matter? Am I over thinking this silly thing?
I've looked at a similar question here: Memory overhead of empty array vs undefined var? in which they were using empty arrays instead of empty strings but I do not know if an empty string takes any less memory than an empty array.
Some clarification to the "memory worth" of these data types and some benchmarking would be greatly appreciated.