Keyboard shortcut to go to a file?
CMD P
Keyboard shortcut to build project?
SHIFT CMD B
Keyboard shortcut to open the Commands Palette?
F1
To perform builds in VS Code, you need to set up a tasks.json file. What’s the easiest way to do this?
This will create a tasks.json file in a .vscode folder with some example entries in it.
What is Optional Static Type Notation?
Typescript can usually infer the type of a variable, making it unnecessary for you to define the type explicitely.
The above declaration has the same affect as the one below.
In Typescript, a boolean value can be:
Is this correct?
No, a boolean can only be either true of false
In Javascript, the two special types undefined and null exist, can these be used in Typescript?
No, use of either of these will generate an error.
typeof and instanceof can be used by a feature called Guard Types. How does this work?
The Typescript compiler understands the use of typeof in the if statement. myVar.Length would be illegal if the typeof was not used to check it’s type first.
var myVar: any;
myVar = 10
if (typeof myVar === ‘string’)
{
return myVar.length;
}
Create a switch statement that assigns the correct age given a name assigned to myName. Assign 99 to myAge if the name is not recognised. The two names that should be recognised are “Graeme” and “John”.
var myAge; var myName = "John"; (or "Graeme")
[Switch statement here]
var myAge;
var myName = "John";
**switch** (myName){
**case**"John":
myAge = 47;
**break**;
**case**"Graeme":
myAge = 45;
**break**;
**default**:
myAge = 99;
}for…in should not be use to iterate over the values of an array Why not, and what similar statement can be used instead?
for..in iterates over keys (or property names) of an object. for…of can be used, it iterates over the values.
let arr = [3, 5, 7];
arr.foo = “hello”;
for (let i in arr)
{ console.log(i); // logs “0”, “1”, “2”, “foo” }
for (let i of arr)
{ console.log(i); // logs “3”, “5”, “7” }
Below are three valid function definitions. What type of definition are each of them.
By default, all properties and methods of a class are declared with what visibility?
Public
In the following class declaration, what effect does the this keyword have.
class Person {
fullname : string;
constructor(firstname : string, lastname : string) {
this.fullname = firstname + “ “ + lastname;
}
}
this donates member access. Specifically, we are saying, access fullname, the member of this class.
Write a statement that will create an object of the following class and assign it to a variable.
class Person {
constructor(firstname : string, lastname : string) { }
}
var myPerson = new Person (“Bill”, “Smith”);
A namespace is used to encapsulate related features. How do you make features within the namespace accessable from outside it?
Use the export keyword. In the example below, we don’t have access to the BatMobile from outside the namespace :(
namespace vehicles {
export class Car { };
export class Van { };
class Batmobile { };
}