# How to access variables declared in a function, from another function using JavaScript?

We have to write a function, that does some simple task, say adding two numbers or something like that. We are required to demonstrate the way we can access the variables declared inside that function in some other function or globally.

## Example

Following is the code −

const num = 5;
// a random number between [0, 10)
const random = Math.floor(Math.random() * 10);
// assigning the random to this object of function
// so that we can access it outside
this.random = random;
this.res = num + random;
};
console.log(result - scopedRandom);
5