I study JavaScript and when I run the code, the tab gives an error out of memory, but there is enough memory


The code is only 20 lines long and when you run it, it gives an error about a lack of memory, I have 4GB of RAM previously this was not observed, I attach a photo. And there is one more question, if someone understood the code, can you explain how the first function (function) can be related to var years? I didn't understand this point, the video explains it but unfortunately I didn't fully understand it. Thank you enter a description of the image here

Author: Ali64, 2020-08-02

1 answers

You have an error in the code

for(var i = 0; 1 < arr.length; i++)

Please change the end condition correctly

for(var i = 0; i < arr.length; i++)

Otherwise, there is an infinite loop with the constant addition of the{[3] element to the array]}

For the second question, your function is not related to this array in any way, only by passing an array in the parameter, you can link them ideally, and so your array is declared globally and in fact visible to all your functions.

 0
Author: Aziz Umarov, 2020-08-02 03:24:50