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
Helaine
2 days ago
C) Outer function's scope
upvoted 0 times
...
Hayley
15 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
6 days ago
C) Outer function's scope
upvoted 0 times
...
Tish
7 days ago
B) Hoisting
upvoted 0 times
...
Luisa
9 days ago
C) Outer function's scope
upvoted 0 times
...
Providencia
13 days ago
B) Hoisting
upvoted 0 times
...
Jovita
14 days ago
A) Inner function's scope
upvoted 0 times
...
Una
22 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
29 days ago
Exactly! It's all about the scope chain.
upvoted 0 times
...
Aileen
1 months ago
C) Outer function's scope
upvoted 0 times
...
Celeste
1 months ago
Oh, I see. That makes sense now.
upvoted 0 times
...
Brandon
2 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
3 months ago
Hmm, that makes sense. Hoisting does allow inner functions to access variables from outer functions.
upvoted 0 times
...
Tyisha
3 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
az-700  pass4success  az-104  200-301  200-201  cissp  350-401  350-201  350-501  350-601  350-801  350-901  az-720  az-305  pl-300  

Warning: Cannot modify header information - headers already sent by (output started at /pass.php:70) in /pass.php on line 77