Menu
Coddy logo textTech

Recap: Introduction to TS

Part of the Introduction To TypeScript section of Coddy's JavaScript journey — lesson 5 of 73.

challenge icon

Challenge

Easy

Create a constant named userId with an explicit type annotation of number and assign it the value 12345.

Create a variable named username with an explicit type annotation of string and assign it the value "john_doe".

You are provided with the following line of code that contains a type error:

username = userId;

Fix this type error by creating a new variable called userIdString that converts the userId to a string using the String() function, then assign userIdString to username instead.

Finally, print both userId and username to the console on separate lines.

Try it yourself

// TODO: Write your code here
// Create the constant userId with type annotation
// Create the variable username with type annotation
// Fix the type error by converting userId to string
// Assign the converted value to username

// Print the results
console.log(userId);
console.log(username);

All lessons in Introduction To TypeScript