I'm trying to make a carousel slider where my slide is as wide as the window, and I'm using the width of that slide to tell the other slides how far off screen they need to be. I'm trying to capture the window width dynamically so that when I resize the window, the width updates automatically without me being able to see the other slides. Can someone explain to me why I'm getting undefined here and tell me how to dynamically update this variable via event listener or otherwise?
let slideWidth;
window.onload = function () {
slideWidth = window.innerWidth;
};
window.onresize = function () {
slideWidth = window.innerWidth;
};
console.log(slideWidth);