Recall & Review
beginner
What is the
any type in TypeScript?The
any type allows a variable to hold any value without type checking. It disables TypeScript's type safety for that variable.Click to reveal answer
beginner
What is the
unknown type in TypeScript?The
unknown type represents any value but requires type checking before using it. It is safer than any because it forces you to check the type before operations.Click to reveal answer
intermediate
How does
unknown improve safety compared to any?unknown forces you to check the type before using the value, preventing errors. any skips checks and can cause runtime errors.Click to reveal answer
intermediate
Can you assign a value of type
any to a variable of type unknown?Yes, you can assign
any to unknown because unknown accepts any value safely.Click to reveal answer
intermediate
Can you assign a value of type
unknown to a variable of type any?Yes,
unknown can be assigned to any because any accepts all types without checks.Click to reveal answer
Which type requires you to check the type before using the value?
✗ Incorrect
unknown requires type checks before usage, making it safer than any.What happens if you use
any type in TypeScript?✗ Incorrect
any disables type checking and allows any value without restrictions.Can you assign a value of type
unknown directly to a variable of type string?✗ Incorrect
You must check or cast
unknown before assigning it to a specific type like string.Which type is safer to use when you don't know the exact type yet?
✗ Incorrect
unknown is safer because it forces type checks before use.What is a key difference between
any and unknown?✗ Incorrect
unknown requires type checks before use, while any disables checks.Explain the difference between
any and unknown types in TypeScript.Think about safety and when you can use the value without checks.
You got /4 concepts.
When should you prefer
unknown over any in your TypeScript code?Consider safety and error prevention.
You got /4 concepts.