Copy and paste the following script.
<script language="ecmascript" type="text/ecmascript">
var groupCollection;
function getSiteGroups() {
var clientContext = new SP.ClientContext();
this.groupCollection = clientContext.get_web().get_siteGroups();
clientContext.load(groupCollection);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded() {
var groupName = 'Site Groups: \n';
var groupsEnumerator = this.groupCollection.getEnumerator();
while (groupsEnumerator.moveNext()) {
var group = groupsEnumerator.get_current();
groupName += group.get_title() + '\n';
}
alert(groupName);
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}</script>
<input id="btnGetSiteGroups" onclick="getSiteGroups()" type="button" value="Get Site Groups" />