Reputation: 2368
This question is more out of curiosity. Is there a way I can call bar() without calling foo() in the code below? Or does this completely anonymize bar()? Furthermore, is there any use case for this sort of syntax?
var foo = function bar() {
console.log('test')
}
foo(); // 'test'
Upvotes: 2
Views: 58
Reputation:
It's because it's scoped inside the function. You can test like this.
var a = 1;
var foo = function bar() {
a++;
console.log('test');
if(a < 3) {
return bar();
}
}
foo();
//test
//test
Upvotes: 2