Visual Studio Code Flashcards

1
Q

Keyboard shortcut to go to a file?

A

CMD P

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Keyboard shortcut to build project?

A

SHIFT CMD B

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Keyboard shortcut to open the Commands Palette?

A

F1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

To perform builds in VS Code, you need to set up a tasks.json file. What’s the easiest way to do this?

A
  • Press F1 to open the Commands Palette
  • Type ‘Configure Task Runner’ and hit enter

This will create a tasks.json file in a .vscode folder with some example entries in it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is Optional Static Type Notation?

A

Typescript can usually infer the type of a variable, making it unnecessary for you to define the type explicitely.

  1. var counter; // unknown (any) type
  2. var counter = 0; // number (inferred)

The above declaration has the same affect as the one below.

  1. var counter : number; // number
  2. var counter : number = 0; // number
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

In Typescript, a boolean value can be:

  1. true
  2. false
  3. 0
  4. 1

Is this correct?

A

No, a boolean can only be either true of false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

In Javascript, the two special types undefined and null exist, can these be used in Typescript?

A

No, use of either of these will generate an error.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

typeof and instanceof can be used by a feature called Guard Types. How does this work?

A

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;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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]

A
var myAge;
 var myName = "John";
**switch** (myName){
**case**"John":
 myAge = 47;
**break**;
**case**"Graeme":
 myAge = 45;
**break**;
**default**:
 myAge = 99;
 }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

for…in should not be use to iterate over the values of an array Why not, and what similar statement can be used instead?

A

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” }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Below are three valid function definitions. What type of definition are each of them.

  1. function greet(name? : string) : string { //function body }
  2. var greet = function(name? : string) : string { //function body }
  3. var greet = (name : string) : string => { //function body }
A
  1. Named function.
  2. Anonymous funciton.
  3. Arrow Function.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

By default, all properties and methods of a class are declared with what visibility?

A

Public

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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;

}

}

A

this donates member access. Specifically, we are saying, access fullname, the member of this class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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) { }

}

A

var myPerson = new Person (“Bill”, “Smith”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

A namespace is used to encapsulate related features. How do you make features within the namespace accessable from outside it?

A

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 { };

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly