How to run js at a certain screen resolution?

Can't make "adaptability" of JS scripts. Doesn't work. I tried this:
$(window).resize(function() {
 if(document.documentElement.clientWidth > 1200) {
 // the script
}
});


and

window.onresize = function(event) {
 if(window.innerWidth >= 1200) {
 // the script
}
});


and

if (document.body.clientWidth>1200){
 // the script
}


Tell me how to do?
June 10th 19 at 15:32
2 answers
June 10th 19 at 15:34
Solution
Why not use media queries? matchMedia
A simple example
var mediaQuery = window.matchMedia("screen and (min-width: 600px)");
mediaQuery.addListener(foo);
foo(mediaQuery);

function foo(mq) {
 document.body.style.backgroundColor = mq.matches ? '#f00' : '#060';
}
June 10th 19 at 15:36
Code looks working.

Find more questions by tags JavaScript