Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Salesforce Exam Javascript Developer I Topic 4 Question 65 Discussion

Actual exam question for Salesforce's Javascript Developer I exam
Question #: 65
Topic #: 4
[All Javascript Developer I Questions]

Refer to the codebelow:

function foo () {

const a =2;

function bat() {

console.log(a);

}

return bar;

}

Why does the function bar have access to variable a ?

Show Suggested Answer Hide Answer
Suggested Answer: C

Contribute your Thoughts:

Dana
2 days ago
Haha, I almost went with B) Hoisting. That would've been a rookie mistake! C is the correct answer, of course.
upvoted 0 times
...
Huey
10 days ago
Definitely C. Closures, baby! The inner function `bat()` has access to the variables in its enclosing function's scope.
upvoted 0 times
...
Chara
11 days ago
The answer is C) Outer function's scope. The nested function `bat()` has access to the variable `a` because it's defined in the outer function `foo()'s scope.
upvoted 0 times
...
Svetlana
18 days ago
Hmm, that makes sense. Hoisting does allow inner functions to access variables from outer functions.
upvoted 0 times
...
Tyisha
19 days ago
I believe it's because of hoisting.
upvoted 0 times
...
Svetlana
23 days ago
I think the function bar has access to variable a because of outer function's scope.
upvoted 0 times
...

Save Cancel