⊗jstsPmBsOVTC 10 of 55 menu

Type checking of object values ​​in TypeScript

When an object is declared, TypeScript remembers the data type of all its elements, and then ensures that those types don't change.

Let's look at the example of our object with the user. Let's declare it:

let user = {name: 'john', age: 30};

After the declaration, TypeScript analyzed the data type of each value and remembered that 'name' is a string, and 'age' is a number.

Now trying to write a value of a different type to the field will result in an error.

Example:

user.name = 123; //

Example:

user.age = 'eee'; //

Example:

user.age = '30'; //

Without running the code, determine what the result of executing the code will be:

let date = {year: 2025, month: 12, day: 31}; date.month = '12'; console.log(date);

Without running the code, determine what the result of executing the code will be:

let product = {code: '123', name: 'apple', price: 12}; product.code = 123; console.log(product);

Without running the code, determine what the result of executing the code will be:

let product = {code: '123', name: 'apple', price: 12 }; product.price = 123; console.log(product);

Without running the code, determine what the result of executing the code will be:

let user = {name: 'john', admin: true}; user.admin = 'false'; console.log(user);
enru