Avatar ·

What is TypeScript and why should you use it instead of JavaScript? Explanation for beginners

Hello everyone! I'm a beginner frontend developer, writing JavaScript for about half a year. Recently at an interview I was asked about TypeScript, and I realized I can't really explain what it is and why it's needed. I've heard that TypeScript is a "superset" of JavaScript, but I don't understand the advantage. JS seems to work fine, why complicate things? I have a small project — an online store on React. I write in pure JS, and sometimes strange bugs occur: for example, a function expects a number, but a string comes in, or I forget to pass an argument. Errors only surface at runtime, and it's annoying. Here's an example of my JS code: ```javascript function calculateTotal(price, quantity) { return price * quantity; } // Somewhere in the code I call: let result = calculateTotal("100", 2); ```