JS vs TS typeof
| Comparison | JavaScript | TypeScript |
|---|---|---|
| Scope | Runtime | Compile-time |
| Returns | a string naming the type ("string", "object") | a type (for example, number, {}) |
| Executes code? | Yes | No |
| Used for | Checks in code (if (typeof x === "string")) | Extracting types from values |
| JS equivalent | Object.keys, typeof | Nothing, this is a purely TS concept |
| Example | typeof 5 -> "number" | typeof 5 -> number |
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.