Writing aan external function to do this would be impossible, and I'll demonstrate that with a proof by contradiction.
Let's assume we've written our magic function called getWhatsInScope
. Now, let's say we want to call it from our function myFunction
and see if it picks up our function variable myVariable
. This is a contradiction because no matter how we write getWhatsInScope
, it can't see myVariable
.
function getWhatsInScope () {
console.log(myVariable) // out of scope
}
function myFunction() {
const myVariable = 42
getWhatsInScope()
}