Independence Day Deal! Unlock 25% OFF Today – Limited-Time Offer - 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:

Willow
1 months ago
Wow, this is a classic closure question. I bet the exam writer is chuckling to themselves, thinking 'Muahaha, let's see if they understand scope!'
upvoted 0 times
Hayley
10 days ago
A) Inner function's scope
upvoted 0 times
...
...
Charlesetta
1 months ago
Wait, is this a trick question? I mean, how can the prototype chain be involved here? C is the obvious choice.
upvoted 0 times
Mireya
1 days ago
C) Outer function's scope
upvoted 0 times
...
Tish
2 days ago
B) Hoisting
upvoted 0 times
...
Luisa
4 days ago
C) Outer function's scope
upvoted 0 times
...
Providencia
8 days ago
B) Hoisting
upvoted 0 times
...
Jovita
9 days ago
A) Inner function's scope
upvoted 0 times
...
Una
17 days ago
A) Inner function's scope
upvoted 0 times
...
...
Dana
2 months 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
Sharen
24 days ago
Exactly! It's all about the scope chain.
upvoted 0 times
...
Aileen
29 days ago
C) Outer function's scope
upvoted 0 times
...
Celeste
1 months ago
Oh, I see. That makes sense now.
upvoted 0 times
...
Brandon
1 months ago
A) Inner function's scope
upvoted 0 times
...
...
Huey
2 months ago
Definitely C. Closures, baby! The inner function `bat()` has access to the variables in its enclosing function's scope.
upvoted 0 times
Quentin
1 months ago
C) Outer function's scope
upvoted 0 times
...
Delila
2 months ago
A) Inner function's scope
upvoted 0 times
...
...
Chara
2 months 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
2 months ago
Hmm, that makes sense. Hoisting does allow inner functions to access variables from outer functions.
upvoted 0 times
...
Tyisha
2 months ago
I believe it's because of hoisting.
upvoted 0 times
...
Svetlana
3 months ago
I think the function bar has access to variable a because of outer function's scope.
upvoted 0 times
...

Save Cancel