JavaScript for Automation: getting the clipboard

In AppleScript, it is possible to get the system clipboard with something like the following:

set s to the clipboard as text

If you run this in Script Editor with “clip” on the clipboard, you should see this:

In JavaScript for Automation (JXA), you can achieve the same thing with the following code:

app = Application('System Events');  
app.includeStandardAdditions = true;  
s = app.theClipboard();

You can also use:

app = Application.currentApplication();  
app.includeStandardAdditions = true;  
s = app.theClipboard();