When you add a new Script connector to your workflow it comes with some example variables and an example script. You can change the variables to anything you want. Within your script variables are referenced using input.name. In the example below the variable foo with the value bar can be referenced by input.foo - you can see in the example that this is being used here to return this variable. Any variable that you return in a script is available to be used in other connectors.
When writing scripts only replace the line return input.foo; in the example script. The function declaration is required to make the script run properly.