0
0
Typescriptprogramming~5 mins

Boolean type behavior in Typescript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A{}
B'false'
C[]
D0
What does the expression !!'0' evaluate to?
Afalse
Btrue
C0
Dundefined
Which operator checks both value and type equality for Booleans?
A===
B!=
C==
D||
What is the Boolean value of null in TypeScript?
Atrue
Bnull
Cfalse
Dundefined
How do you convert a number to a Boolean explicitly?
AUsing <code>Boolean()</code>
BUsing <code>Number()</code>
CUsing <code>String()</code>
DUsing <code>parseInt()</code>
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.