Kotlin - FunctionsWhy might a Kotlin developer prefer a local function over a lambda expression inside a function?ALocal functions cannot access outer variables.BLocal functions are always faster than lambdas.CLocal functions must be declared at the top level.DLocal functions can be recursive and have named parameters.Check Answer
Step-by-Step SolutionSolution:Step 1: Compare local functions and lambdasLocal functions support recursion and have explicit names and parameters, unlike lambdas which are anonymous and harder to recurse.Step 2: Evaluate optionsLocal functions can access outer variables. Performance is not always better. Local functions are declared inside functions.Final Answer:Local functions can be recursive and have named parameters. -> Option DQuick Check:Local function advantage = recursion and naming [OK]Quick Trick: Local functions allow recursion; lambdas do not easily [OK]Common Mistakes:MISTAKESAssuming local functions are always fasterThinking local functions cannot access outer scopeBelieving local functions must be top-level
Master "Functions" in Kotlin9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Kotlin Quizzes Collections Fundamentals - Array creation and usage - Quiz 8hard Control Flow as Expressions - When with ranges and types - Quiz 2easy Control Flow as Expressions - Smart casts in when and if - Quiz 12easy Data Types - Any type as universal base - Quiz 9hard Functions - Parameters with default values - Quiz 3easy Functions - Function declaration syntax - Quiz 13medium Loops and Ranges - For loop with ranges - Quiz 3easy Operators and Expressions - Range operator (..) and in operator - Quiz 9hard Variables and Type System - String templates and interpolation - Quiz 14medium Variables and Type System - Val for immutable references - Quiz 8hard