As @Rounin says, window.matchMediais the equivalent of CSS @media queries. But the coolest part is not only what you can check with .matches- it's amazing that you can add an event listener that fires when the state changes.
, - , 500 - , > 500 , , < 500px
.matches, , , , @Rounin, -.
let widthMatch = window.matchMedia("(min-width: 500px)");
widthMatch.addEventListener('change', function(mm) {
if (mm.matches) {
document.body.addEventListener( etc. );
}
else {
}
});