How to copy to clipboard using JavaScript

A time ago the only way to copy to browser’s clipboard was from a button in the app using Flash but with modern browsers we can achieve copy to clipboard using javascript, without using any plugin.