In addition to media queries with CSS I want JavaScript to also perform some actions based on screen/browser width.

As an example, when the browser is extended greater than 1400px as well as media queries showing more options in the top navigation bar, I would like JavaScript to perform an Ajax request to get additional data. This is just an example, but I want to do various things like this.

I only need to know a cross-browser and reliable way to detect the browser width so JS returns exactly the same value as media queries does?

This should detect it correctly on desktops, laptop, tablets and mobiles.