TypeScript Fundamentals
by Kwiz
Qs
18
Difficulty
Mid
Plays
1
Record
n/a
Description

This TypeScript fundamentals quiz will cover the basics of type declaration, TypeScript errors and best practices.

Question Preview
What's the difference between a let variable declaration and a const variable declaration?
Question Preview
What is the benefit of type inference?
Question Preview
What message will TypeScript communicate to us based on the following code?
let x = "hello, world!";

x = "hello, mars!";

x = 42;
Question Preview
What will TypeScript infer the type of the following code to be?
const y = "hello world";  
Question Preview
The following code is valid according to TypeScript
const y = "hello world";

function print(arg: "hello mars") {}

foo(y);


Question Preview
What is the file extension of a TypeScript declaration file?
Question Preview
Will TypeScript complain when we try to change the value of the foo property in the following code?
const obj = {
  foo: "hello"
}

obj.foo = "world"; // ?
Question Preview
What is the most flexible type in TypeScript?
Question Preview
Which of the following is the correct syntax for a simple (non-inferred) type annotation?
Question Preview
TypeScript can always infer type from variables with initializers
Question Preview
The following code is a valid way to add a type to an array
let a: number[] = [];
Question Preview
What is the expected type for elements in the following array?
let a: number[] = [];
Question Preview
Select the correct 3 words to complete this output based on the code below: _________ Argument of ______ "a" is not assignable to _______ of type "number"
let a: number[] = [];
a.push(10);
a.push("a");
Question Preview
What is the inferred type of the following code?
let a = [];
Question Preview
What is the advantage of using a tuple value?
let exampleTuple: [number, string, string] = [10, "hello", "world"];
Question Preview
How can we define & initialize a tuple that takes 2 numbers?
Question Preview
What is the TypeScript issue with the following code?
let obj = {
  foo: number;
  bar: string;
}

obj = {
  foo: 10
}
Question Preview
When defining types within an object, which operator means the property is optional?