Typescript 102 // Data & Variables Flashcards

1
Q

What is a variable?

A

Variable Definition: A variable is a user-defined storage of data

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

What is a variable declaration/initialisation?

A

A variable must be declared before using in a program. Declaration is stating the variable name with the keyword, essentially reserving the memory space. Initialisation is giving that declared variable a value.

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

What is good practice for declaring variables that have no value?

A

Initialise to 0 or Null

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

What are the 3 keywords used to declare variables

A

let, const, var

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

What is the initialisation syntax for a LET declaration?

A
let var_name = value;
(e.g. let num1 = 5; )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How many times can you declare the same variable with the keyword LET?

A
Once only; the let declaration does not allow for redeclaration, only changing the value stored. In other words, there is no need to use let when changing values.
(e.g. let num1 = 5;
num1 = 6;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the characteristic of a variable declared with const (as opposed to let or var)?

A

It is constant and cannot be reassigned.

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

Which variable declaration keywords allow for reassigning variables to new values?

A

let & var.

const reassignment is invalid.

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

What is the declaration syntax for a CONST declaration?

A
const var_name = value;
(e.g. const num1 = 5; )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Why is initialisation essential when declaring using const?

A

It is not possible to reassign the variable when using const, so the first declaration must contain the data value it is assigned to.

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

What is the similarity between LET and VAR variable declarations

A

They store the variable as a modifiable value.

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

What is the declaration syntax for a var declaration?

A
var var_name = value;
(e.g. var num1 = 5; )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Why is let generally preferable to var?

A

Compiler errors: If something has gone wrong the compiler will show up, meaning problems can be more easily caught

Linearity: let variables cannot be used before declaration, which encourages linearity in the code

Single Declaration: Makes it less likely for accidental reassignment errors.

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

Typescript has the ability to add static typing to variable declarations. What is static typing?

A

Static typing is the ability to make a variable always of the same type, meaning if the wrong data type is used there will be a compiler error.

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

What is the typescript static typing initialisation Syntax?

A

let var_name:datatype = value;
const var_name:datatype = value;
var var_name:datatype = value;
(e.g. let num1:number = 5;)

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

What are the valid characters for variable names

A

Letters, Underscores and Numbers.

NUMBERS NOT VALID AT THE START)

17
Q

What are the primary data types in Javascript/Typescript?

A

Number, string, boolean, valueless.

18
Q

What is the difference between Typescript and Javascript Type Inference styles.

A

After initialisation, Javascript allows for reassigning data type of variable.
Typescript does not allow for reassignment of data type, regardless of type static typing specified.

19
Q

In typescript declarations, what does the colon mean?

A

“of the type”.