Mengubah Nilai dalam TypeScript

Misalkan kita memiliki suatu variabel string:

typescriptlet test: string = 'abc';

Mari kita berikan nilai string lain ke dalamnya:

typescriptlet test: string = 'abc';
test = 'def';

Sekarang mari kita coba berikan angka ke dalamnya. Dalam hal ini TypeScript akan memberikan error, karena kita mencoba mengubah tipe variabel:

typescriptlet test: string = 'abc';
test = 123; // akan menghasilkan error
Задание 1

Tanpa menjalankan kode, tentukan apa hasil dari eksekusi kode berikut:

typescriptlet test: number = 123;
test = 'abc';

console.log(test);
Задание 2

Tanpa menjalankan kode, tentukan apa hasil dari eksekusi kode berikut:

typescriptlet test: string = 'abc';
test = 123;

console.log(test);
Задание 3

Tanpa menjalankan kode, tentukan apa hasil dari eksekusi kode berikut:

typescriptlet test: string = 'abc';
test = '123';

console.log(test);
Задание 4

Tanpa menjalankan kode, tentukan apa hasil dari eksekusi kode berikut:

typescriptlet test: string = 'abc';
test = true;

console.log(test);
Задание 5

Tanpa menjalankan kode, tentukan apa hasil dari eksekusi kode berikut:

typescriptlet test: string = 123;
test = 'abc';

console.log(test);
Задание 6

Tanpa menjalankan kode, tentukan apa hasil dari eksekusi kode berikut:

typescriptlet test: string = '123';
test = '456';

console.log(test);
Задание 7

Tanpa menjalankan kode, tentukan apa hasil dari eksekusi kode berikut:

typescriptlet test: number = '123';
test = '456';

console.log(test);
Задание 8

Tanpa menjalankan kode, tentukan apa hasil dari eksekusi kode berikut:

typescriptlet test: number = 123;
test = 456;

console.log(test);
Задание 9

Tanpa menjalankan kode, tentukan apa hasil dari eksekusi kode berikut:

typescriptlet test: boolean = true;
test = false;

console.log(test);