So they always have the latest and most accurate information. Essentially, all NodeList objects are queries that run in real time when accessing a DOM document. For example, the following code will cause an infinite loop:
If you want to iterate over a NodeList, it is best to initialize a second variable using the length property and then compare the iterator to that variable. As shown in the following code:
Summary: Generally speaking, the number of visits to NodeList should be minimized. Because every time a NodeList is accessed, a document-based query is run. Therefore, you can consider caching the values obtained from NodeList, as shown in Example 2!