Core JS mentors interview #2
TypeScript
- What is the difference between TypeScript and JavaScript, and why would you choose TypeScript for a project?
- Explain what structural typing is in TypeScript and how it differs from nominal typing.
- What are the primitive types in TypeScript, and how are they different from JavaScript’s types?
- How do
Partial<T> and Required<T> utility types differ, and why would you use them in your code?
- What is the difference between
never and void in TypeScript, and when would you use each?
- What are generics in TypeScript, and how can they make functions or classes more reusable? Provide examples.
- How does the
Pick<T, K> utility type differ from Omit<T, K>, and when would you use each of them?
- Describe the difference between
any and unknown in TypeScript and discuss scenarios where one should be preferred over the other.
- How does the use of
interface differ from type in TypeScript, and when would you choose one over the other?
- What is the purpose of the
readonly modifier in TypeScript, and how does it differ from a const variable?
Object-Oriented Programming (OOP)
- What is the difference between
public, private, protected and static members in a TypeScript/JavaScript class, and what are their use cases?
- Discuss SOLID principles and how they apply to Object-Oriented Programming in JavaScript or TypeScript.
- What is the
instanceof operator in JavaScript, and how does it work when checking if an object belongs to a specific class?
- How do ES2015 classes simplify creating objects compared to traditional functions and prototypal inheritance in JavaScript?
- Explain how you can achieve multiple inheritance in TypeScript and how it differs from extending classes in traditional OOP.
Async JavaScript
- What is the difference between
setTimeout and setInterval in JavaScript, and how can you stop them from running?
- What are
Promise.all() and Promise.race(), and how do they differ in their behavior when resolving multiple promises?
- How does
async/await syntax enhances the readability and maintainability of asynchronous JavaScript code compared to traditional promise chains?
- What is the role of the
finally block in error handling, and how does it interact with try and catch blocks in JavaScript?
- How can you create and
throw a custom error in JavaScript, and why would you do so? Provide a practical example.