there is a checkbox and there is such a script :
-why lastChecked = this in the console gives the last and the penultimate selected item ?;
-why at this location in the handleCheck() function in the console handleCheck() last and penultimate selected item, but if lastChecked = this put before console.log will lastChecked = this the same last marked item?
- where can I find out more about reassigning this inside a function, trying to find it, do all links of this lead to this in object ?
const checkboxes = document.querySelectorAll('.item input[type="checkbox"]'); let lastChecked; function handleCheck() { console.log(this); console.log(lastChecked); lastChecked = this; } checkboxes.forEach(checkbox=> checkbox.addEventListener('click', handleCheck)) <div class="inbox"> <div class="item"> <input type="checkbox"> <p>item one</p> </div> <div class="item"> <input type="checkbox"> <p>item two</p> </div> <div class="item"> <input type="checkbox"> <p>item three</p> </div> </div>