Skip to main content

JS vs TS typeof

ComparisonJavaScriptTypeScript
ScopeRuntimeCompile-time
Returnsa string naming the type ("string", "object")a type (for example, number, {})
Executes code?YesNo
Used forChecks in code (if (typeof x === "string"))Extracting types from values
JS equivalentObject.keys, typeofNothing, this is a purely TS concept
Exampletypeof 5 -> "number"typeof 5 -> number

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.