How to get the viewport size: jQuery's $(window).width() is highly regarded as cross-broswer compatible. JavaScript's document.documentElement.clientWidth is fasterand nearly as cross-broswer compatible. Consider using document.documentElement.clientWidthand a fallback to $(window).width() when jQuery is available. The tables below compare these live against the less reliable inner/outer methods:
How to get the device size: It's simple. Use window.screen.width for device width and window.screen.height for device height. The .availWidth/.availHeight methods give you the device size minus UI taskbars (try on an iPhone) and are slower outside of Webkit. Device size is static and does not change when the page is resized or rotated.
For further comparison, here are document size methods (not usually needed for responsive design but useful in other regards such as scrolling apps). Note the difference between $(document).width() and document.body.clientWidth when the window is wider than the max-width of the body: