Recall & Review
beginner
What are the two possible values of a Boolean type in TypeScript?
The Boolean type in TypeScript can only have two values: true or false.
Click to reveal answer
intermediate
How does TypeScript treat non-Boolean values in a Boolean context?
TypeScript uses JavaScript's truthy and falsy rules. Values like
0, '' (empty string), null, undefined, and NaN are treated as false. Others like non-empty strings or numbers (except 0) are true.Click to reveal answer
beginner
What is the result of
Boolean('hello') in TypeScript?The result is true because non-empty strings are considered truthy.
Click to reveal answer
intermediate
Explain the difference between
== and === when comparing Boolean values.== compares values after type coercion, so 1 == true is true. === compares both value and type, so 1 === true is false. It's best to use === to avoid unexpected results.Click to reveal answer
beginner
How can you explicitly convert a value to a Boolean in TypeScript?
You can use the
Boolean() function or double negation !!value to convert any value to a Boolean.Click to reveal answer
Which of the following values is considered falsy in TypeScript?
✗ Incorrect
0 is falsy. Non-empty strings ('false'), empty arrays ([]), and empty objects ({}) are truthy.
What does the expression
!!'0' evaluate to?✗ Incorrect
The string '0' is non-empty, so it is truthy. Double negation converts it to true.
Which operator checks both value and type equality for Booleans?
✗ Incorrect
=== checks both value and type equality.What is the Boolean value of
null in TypeScript?✗ Incorrect
null is falsy, so its Boolean value is false.How do you convert a number to a Boolean explicitly?
✗ Incorrect
Use
Boolean() to convert any value to a Boolean.Describe how TypeScript treats different values when used in a Boolean context.
Think about which values become true or false when converted.
You got /4 concepts.
Explain the difference between == and === when comparing Boolean values in TypeScript.
Focus on how type affects equality.
You got /4 concepts.