There are two easy ways to accomplish this.
OR use modernizr http://modernizr.com/docs/. <- scroll down to near the bottom, look for Modernizr.mq().
Modernizr has a mq() method which takes a media-query like you would write it in css and returns true or false based on whether that media query applies to the current view. I’ve used this before to handle logic which differs on small and large screens and it worked great.