Enjoy free content straight from your inbox 💌
00:00
Modern JavaScript allows you to create a variable as a cons declaration. Of course, we can use type annotations with cons. Declarations, for example. Hey, we have a type point with members X and Y, and we can annotate this point variable to be of type point. This ensures that any mistakes we make during the initialization of the variable are caught at compile time. For example, a typo in the X property. Now, the key difference between a constant declaration and a lead declaration in JavaScript is that you cannot reassign a variable that has been declared with constant.
00:33
For example, if you try to reassign with the equals operator, a new object to the point variable, we get a compile time error from TypeScript. Of course, this is because reassigning to a cons would blow up at runtime in JavaScript. Beyond this reassign ability protection, there are no other guarantees offered by a JavaScript cons declaration. For example, we can still go ahead and modify the properties of an object. TypeScript understands this JavaScript behavior and will allow you to do the same in your TypeScript code.