Question: How can I determine if a variable exists from within the Groovy code running in the Scripting Engine?

The variable was put by [ScriptEngine's put method](https://docs.oracle.com/javase/8/docs/api/javax/script/ScriptEngine.html#put(java.lang.String,%20java.lang.Object))

Answer: 
In a [groovy.lang.Script](http://docs.groovy-lang.org/latest/html/api/groovy/lang/Script.html) there is a method `public Binding getBinding()`. And [groovy.lang.Binding](http://docs.groovy-lang.org/latest/html/api/groovy/lang/Binding.html) has method `public boolean hasVariable(String name)`.

Thus you can simply check variable existence like:

```
if (binding.hasVariable('superVariable')) {
// your code here
}

```
Variables injected by the Scripting Engine are held within
`binding.variables`, so you can e.g. check for variable named `xx`:

```
if (binding.variables["xx"]) ...

```