Avatar ·

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

Hi everyone! I'm a beginner frontend developer, writing JavaScript for about six months. I constantly hear that all cool projects are switching to TypeScript, but I don't fully understand why it's needed. JS seems to work fine. Here's an example: I write a function for summing up items in a cart: ```typescript function calculateTotal(price, quantity) { return price * quantity; } let total = calculateTotal("100", 2); // Error: string instead of number console.log(total); // "1002" — concatenation, not multiplication! ``` Because of JS's dynamic typing, I can pass a string instead of a number, and the code will just break logically, but there will be no error. I have to spend a lot of time debugging. I've seen that TypeScript supposedly adds types, but I don't understand how much it actually helps. Can you explain