InterviewSolution
Saved Bookmarks
| 1. |
What is the typeof operator? How is it used in TypeScript? |
|
Answer» Similar to JavaScript, the typeof operator in TypeScript returns the type of the operand as a string. console.log(typeof 10); // "number"console.log(typeof 'foo'); // "string"console.log(typeof false); // "boolean"console.log(typeof bar); // "UNDEFINED"In TypeScript, you can USE the typeof operator in a type context to REFER to the type of a PROPERTY or a variable. let greeting = "HELLO";let typeOfGreeting: typeof greeting; // similar to let typeOfGreeting: string |
|