if you want to check the width screen in the device every 1 second you can do
setInterval(function() {
if (window.matchMedia('(max-width: 767px)').matches) {
alert('here')
} else {
alert('i am ')
}
}, 1000);