Changing Values in TypeScript
Let's say we have some string variable:
let test: string = 'abc';
Let's write another string value into it:
let test: string = 'abc';
test = 'def';
Now let's try to write a number into it. In this case, TypeScript will throw an error, since we are trying to change the type of the variable:
let test: string = 'abc';
test = 123; // will give an error
Without running the code, determine what the result of executing the code will be:
let test: number = 123;
test = 'abc';
console.log(test);
Without running the code, determine what the result of executing the code will be:
let test: string = 'abc';
test = 123;
console.log(test);
Without running the code, determine what the result of executing the code will be:
let test: string = 'abc';
test = '123';
console.log(test);
Without running the code, determine what the result of executing the code will be:
let test: string = 'abc';
test = true;
console.log(test);
Without running the code, determine what the result of executing the code will be:
let test: string = 123;
test = 'abc';
console.log(test);
Without running the code, determine what the result of executing the code will be:
let test: string = '123';
test = '456';
console.log(test);
Without running the code, determine what the result of executing the code will be:
let test: number = '123';
test = '456';
console.log(test);
Without running the code, determine what the result of executing the code will be:
let test: number = 123;
test = 456;
console.log(test);
Without running the code, determine what the result of executing the code will be:
let test: boolean = true;
test = false;
console.log(test);