0
0
Typescriptprogramming~15 mins

Parameters type in Typescript - Mini Project: Build & Apply

Choose your learning style9 modes available
Parameters type
📖 Scenario: You are creating a simple program to greet users with their names and ages.
🎯 Goal: Build a TypeScript function that takes parameters with specific types and prints a greeting message.
📋 What You'll Learn
Create a function with typed parameters
Use string and number types for parameters
Call the function with correct arguments
Print the greeting message
💡 Why This Matters
🌍 Real World
Functions with typed parameters help catch mistakes early and make code easier to understand in real projects.
💼 Career
Knowing how to use parameter types is essential for writing safe and clear TypeScript code in professional development.
Progress0 / 4 steps
1
Create a function with typed parameters
Create a function called greet that takes two parameters: name of type string and age of type number.
Typescript
Need a hint?

Use the syntax function functionName(param1: type1, param2: type2) { } to define typed parameters.

2
Add a greeting message inside the function
Inside the greet function, create a variable called message that uses a template string to combine name and age into the text: Hello, my name is {name} and I am {age} years old.
Typescript
Need a hint?

Use backticks ` and ${variable} to create a template string.

3
Print the greeting message inside the function
Add a console.log statement inside the greet function to print the message variable.
Typescript
Need a hint?

Use console.log(variable) to print to the console.

4
Call the function with arguments
Call the greet function with the arguments "Alice" for name and 30 for age.
Typescript
Need a hint?

Call the function by writing greet("Alice", 30);