Bird
0
0

Identify the error in this Angular TypeScript code:

medium📝 Debug Q14 of 15
Angular - TypeScript in Angular
Identify the error in this Angular TypeScript code:
function addNumbers(a: number, b: number): number {
return a + b;
}
console.log(addNumbers(5, '10'));
ASyntax error: missing semicolon
BNo error, outputs 15
CRuntime error: cannot add number and string
DType error: second argument should be a number
Step-by-Step Solution
Solution:
  1. Step 1: Check function parameter types

    The function expects two numbers as arguments.
  2. Step 2: Analyze the function call

    The second argument is a string '10', which violates the number type requirement, causing a compile-time type error.
  3. Final Answer:

    Type error: second argument should be a number -> Option D
  4. Quick Check:

    Type mismatch error = A [OK]
Quick Trick: Check argument types match function parameters [OK]
Common Mistakes:
  • Assuming string '10' converts automatically
  • Expecting runtime error instead of compile-time error
  • Ignoring TypeScript type checks

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes