a/b testing an alternative script rather than a URL

So the a/b testing I know, is Google Analytics Experiments, testing one URL against another. But I was wondering is there a way to test a different script?

i.e.

if(visitor test a) {load script a}
else {load script b}

Then it would track which script converted best. Within the script I could include anything, it could be as basic as a new headline, or as advanced as a search filtering system to test.

Is this possible? If so how is it achieved? Presumably not through GA. And is there a name for such tests?