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 JS-Dev-101 Exam - Topic 2 Question 13 Discussion

Posted by Brynn on Aug 16, 2026 at 04:06 AM

Why does second have access to variable a?

Suggested Answer: B

The answer is B because JavaScript uses lexical scope.

When a function is created inside another function, the inner function can access variables from the outer function where it was defined.

For example:

function first() {

let a = 10;

function second() {

console.log(a);

}

second();

}

Here, a belongs to the outer function first(). The inner function second() can access it because JavaScript looks for variables through the scope chain.

The lookup works like this:

1. Look inside second()

2. If not found, look inside first()

3. If not found, look in the global scope

Since a is found in the outer function's scope, second() can use it.

This is also the basis of a closure. A closure allows an inner function to remember and access variables from its outer lexical environment.

Why the other options are incorrect:

A is not the best answer because a is not declared inside second() itself.

C is incorrect because the prototype chain is used for object property lookup, not local variable scope lookup.

D is incorrect because hoisting explains how declarations are moved during compilation, but it does not explain why an inner function can access an outer function's variable.

Therefore, the verified answer is B.


Get Premium JS-Dev-101 Questions as Interactive Web-Based Practice Test or PDF Real Exam Format Detailed Explanations Instant Access Get Your Practice Test
14 comments · newest first
VE
Veronika 23 hours ago
I agree with Paz, A makes the most sense!
CH
Chaya 6 days ago
Wait, how does hoisting relate to this?
GL
Glory 11 days ago
No way, it's not C) Prototype Chain!
ST
Stephen 16 days ago
I think it's B) Outer function's scope, right?
PA
Paz 22 days ago
It's definitely A) Inner function's scope.
EL
Elly 27 days ago
I disagree, I think it could be C) Prototype Chain.
LI
Lindsey 1 month ago
Wait, how does that even work?
ME
Melvin 1 month ago
A makes the most sense to me!
DE
Detra 1 month ago
I thought it was B) Outer function's scope?
JO
Johna 2 months ago
It's definitely A) Inner function's scope.
BE
Belen 2 months ago
I’m confused about the options. I thought hoisting was related to variable declarations, so D doesn’t seem right to me.
TO
Tonette 2 months ago
This question feels familiar, like one of the practice questions we did on closures. I’m leaning towards A or B.
LE
Leontine 2 months ago
I remember something about inner functions having access to outer variables, so maybe it's A) Inner function's scope?
ZA
Zana 2 months ago
I think it might be B) Outer function's scope, but I'm not entirely sure how that works with closures.
0/2000 characters

Save Cancel