Bird
0
0

Which of the following is the correct syntax to use let with a nullable variable num to print its double value?

easy📝 Syntax Q3 of 15
Kotlin - Null Safety
Which of the following is the correct syntax to use let with a nullable variable num to print its double value?
Anum?.let { println(it * 2) }
Bnum.let { println(it * 2) }
Cnum?.let println(it * 2)
Dnum?.let { println(num.length) }
Step-by-Step Solution
Solution:
  1. Step 1: Identify safe call usage

    Only num?.let safely calls let if num is not null.
  2. Step 2: Check lambda syntax

    The lambda block must be inside curly braces { } and use it to refer to num.
  3. Final Answer:

    num?.let { println(it * 2) } -> Option A
  4. Quick Check:

    Correct let syntax with safe call = num?.let { println(it * 2) } [OK]
Quick Trick: Always use curly braces and it inside let lambda [OK]
Common Mistakes:
MISTAKES
  • Omitting curly braces for lambda
  • Using variable name instead of it inside lambda
  • Calling let without safe call on nullable

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes