how to set DOM media query in javascript?

I need to write a code in DOM Javascript by using media query.

This is my code,

@media screen and (min-width: 300px){
#demo{
width: 100%;
height: 300px;
background-color: blue;
}
}
I tried this in CSS but isn’t worked.

Now, I need to work this code in DOM Javascript but without using “if-else” conditions. it’s my problem.