Parameter Type Annotations in TypeScript
📖 Scenario: You are building a simple calculator function that adds two numbers. To make your code clear and safe, you want to specify the types of the inputs.
🎯 Goal: Create a function called add that takes two numbers as parameters with type annotations and returns their sum.
📋 What You'll Learn
Create a function named
add with two parameters: a and b.Add type annotations to both parameters to specify they are numbers.
Return the sum of
a and b.Call the
add function with arguments 5 and 7 and print the result.💡 Why This Matters
🌍 Real World
Type annotations are used in real projects to make code easier to understand and safer by preventing wrong types from being used.
💼 Career
Many programming jobs require writing TypeScript with proper type annotations to maintain large codebases and reduce bugs.
Progress0 / 4 steps