This is because the variable is defined after the function is called.
You can do this. It will work.
var firstCallFlag = 1;
__getUserByRmId('sun1')
function __getUserByRmId(rmId) {
console.log(firstCallFlag);
}
By the way, hoisting is JavaScript's default behavior of moving all declarations to the top of the current scope. So, something like this should work.
firstCallFlag =1 ;
__getUserByRmId('sun1')
function __getUserByRmId(rmId) {
console.log(firstCallFlag);
}
var firstCallFlag;
However, JavaScript Initializations are Not Hoisted. Thus, the code like below will consider the variable firstCallFlag undefined.
__getUserByRmId('sun1')
function __getUserByRmId(rmId) {
console.log(firstCallFlag);
}
var firstCallFlag = 1;