1
Hello, I am studying javascript and performing some tests and I would like to understand why this form of call generates error.
function test (){
function printA(){
console.log("a");
}
}
test.printA();
Uncaught TypeError: test.printA is not a function
at <anonymous>:1:6
function test (){
function printA(){
console.log("a");
}
printA();
}
test();
a
Hi Luiz! Take a look at these other questions. If you still have doubts clarifies better here to answer.
– Sergio
I thought it was something related to the scope, but I didn’t know how to explain it. Could you see if my understanding is correct? The "printA" function is in the local scope of "test", so it can only be accessed through "test" or assigned to an object, correct?
– Programmer goblin
Exact! functions and variables declared within the scope of a function are not accessible outside.
– Sergio