You didn't show us all of your code, so it's impossible to tell. But I'm betting that your actual code (and I could be wrong, please correct me if I am) looks something like this:
var noteCount = "";
jsonRequest('media.getFiles', params,
function(result) { noteCount = result['totalCount']},
function(exception) { noteCount = "0"},
true
);
console.log(noteCount);
At which point, the expected behaviour would be for the console to log an empty string.
This is because jsonRequest is (again I'm assuming here) probably set to asynchronous (perhaps the third parameter - true - means it's an asynchronous request?).
So, what happens in your code is the following:
1. set a new variable noteCount to an empty string.
2. create a new jsonRequest object with callback functions when the data is returned
3. While the jsonRequest object is awaiting the data, log the current value of noteCount (an empty string) to the console
4. The jsonRequest has probably returned data by now so call one of the callback functions
If the value of noteCount is important for you to continue, then you can only 'do' other things when noteCount data has been successfully returned.
There's one of two ways to do this - make the request synchronous (not good, 'freezes' the current JS script) or, request the next step in your application in your jsonRequest callback function.
Hopefully I didn't make this explanation too confusing.