Function window.matchMedia()

The Window interface’s matchMedia() method returns
a new MediaQueryList object that can then be used
to determine if the document matches the media
query string.

let mql = window.matchMedia("(max-width: 600px)");
window.matchMedia('(prefers-color-scheme: dark)');

Return value:

A new MediaQueryList object for the media query.
Use this object’s properties and events to detect
matches and to monitor for changes to those
matches over time.

MediaQueryList properties: