Bird
0
0

Which statement about nested functions in Swift is TRUE?

easy📝 Conceptual Q2 of 15
Swift - Functions
Which statement about nested functions in Swift is TRUE?
ANested functions must be declared outside any other function
BNested functions cannot return values
CNested functions are automatically executed when the outer function runs
DNested functions can access variables from their enclosing function
Step-by-Step Solution
Solution:
  1. Step 1: Check variable access rules

    Nested functions can use variables declared in their outer function because they share the same scope chain.
  2. Step 2: Evaluate other options

    Nested functions can return values, must be declared inside another function, and are not executed automatically unless called.
  3. Final Answer:

    Nested functions can access variables from their enclosing function -> Option D
  4. Quick Check:

    Nested functions access outer variables = True [OK]
Quick Trick: Nested functions share outer function's variables [OK]
Common Mistakes:
  • Assuming nested functions run automatically
  • Believing nested functions can't return values
  • Thinking nested functions are top-level

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes