Yep, but pay attention to write a valid javascript code (you should be able to read an error if you open the browser’s console with f12). writing background... as is is an invalid statement in javascript, what you want the script to produce is a string, hence the quotation marks in the on/off example you quoted.
To make it valid, you’d need to declare that variable:
var backgroundImage = "..."
But unfortunately that’s not enough to fix it: under the hood, #{} blocks prepend a return statement to the code. So the code would still be invalid because you can’t write return var somevariable = "etc".
Also, declaring a javascript variable called backgroudImage doesn’t automatically assign the css property “background-image”: in the end #{} and JS{{}} blocks are simply replaced with the value returned by the code they contain (provided it is valid of course) and the property’s content will be evaluated afterwards.