Please wrap your code snippets in tags.
//Declare this at the global scope
var myGlobalVariable;
function countfeat(type,select) {
var selectedOption=select.options[select.selectedIndex];
query = new esri.tasks.Query();
query.where = type + " Like '%" + selectedOption.value + "%'";
queryTask = new esri.tasks.QueryTask("http://vdid-gisedn-2:8399/arcgis/rest/services/flow_BRID/MapServer/0");
queryTask.executeForCount(query, function(count){
alert(count); //it works here with a correct number returned
//Yes, and this is where you assign the value to your variable, but you can only use the value AFTER this has been done
alert("myGlobalVariable = " + myGlobalVariable); //Will have a value of undefined the first time this runs, thereafter will have the previous value...unless you clear it between calls
myGlobalVariable = count;
alert("myGlobalVariable = " + myGlobalVariable); //Will now have the value of count
});
};
//Hook this function up to a button, it will allow you to check the value of the global variable
function testValue(){
alert("myGlobalVariable = " + myGlobalVariable); //This will show undefined until the callback of executeForCount has run
}
I really think you'd benefit from investing some time learning some of the fundamentals of JavaScript (and programming concepts in general) things like scope, closures, asynchronous patterns etc. etc.
Here's a start on the JS stuff:
https://developer.mozilla.org/en-US/docs/JavaScript/Guide