window.matchMedia() allow to listen to browser window size changes and trigger the callback for different media query size.
let mql = window.matchMedia('(max- 600px)');
you can attach a listener to it:
mql.addListener(() => console.log('changes'));
So when the window size is smaller than 600px, it matches is true otherwise is false.
When you resize the window, it will log out "changes" in console.