Without looking at the code it's hard to decide whether there is a way to write the code which will prevent the error, but one solution is that you can put in your file:
// jshint unused:false
Which will disable that check for the file.
Another option might be to tell jshint that you are exporting that variable (though I am not sure if this is exactly correct from your description), with:
/* exported selectcourses
*/
See jshint docs for more details
Note: I've experienced various problems with jshint's detection of these situations, and we've moved to eslint for Moodle 3.2 onwards (MDL-52127).