TypeScript vs JavaScript | Bondar Academy
Course: JavaScript for Testers
Module: JavaScript Fundamentals
Instructor: Artem Bondar
Lesson Summary
This lesson covers the key differences between JavaScript and TypeScript , two programming languages that share similar syntax but differ primarily in their handling of data types. Main Differences Strict Typing: TypeScript supports strict typing, while JavaScript does not. Transcoding: TypeScript code is compiled back into JavaScript when executed. Error Prevention: TypeScript helps prevent errors by enforcing type constraints, reducing mistakes in complex codebases. TypeScript Syntax To begin coding in TypeScript, create a file with the .ts extension. For example: lesson10.ts In TypeScript, when declaring variables, you can specify their types. For example: let customerFirstName: string = "John"; let customerAge: number = 25; If you attempt to assign a value of a different type, TypeScript will throw an error: customerFirstName = 100; // Error: Type 'number' is not assignable to type 'string' Custom Types TypeScript allows the creation of custom types to enforce data integrity: type Customer = { firstName: string; lastName: string; isActive: boolean; }; When creating a variable of this custom type, it must adhere to the defined structure: let firstCustomer: Customer = { firstName: "Mary", lastName: "Jones", isActive: true }; Conclusion The primary advantage of TypeScript is its strict typing , which helps maintain data integrity and reduces runtime errors, unlike JavaScript, where type errors may only be discovered during execution.