Coercion Flashcards

1
Q

Generally speaking, you’re most likely to find strongly typed languages where?

A

Within programming languages that are compiled.

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

Name a few compiled languages.

A

C and C++

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

Why is Java an exception?

A

Java is not necessarily compiled into binary executables but to bytecode that is interpreted by a third party piece of software.

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

What is another name for dynamically typed languages?

A

Weakly typed

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

What must you do in strongly typed languages for functions?

A

Denote the type of information a function will return. i.e. public boolean isAlive() { return true; }

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

Define Coercion.

A

In computer science, type conversion, typecasting, and coercion are different ways of, implicitly or explicitly, changing an entity of one data type in another.

In simple terms, this would be how you take on data type and convert it into another.

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

Difference between coercion and conversion.

A

Coercion could be thought of how an interpreter or compiler works to determine what kind of comparison is being made, whereas conversion is an explicit change in type that we, as the programmer, write in our code.

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

When you take a variable of one type and convert it’s value to another type when performing an operation or evaluation, is called what?

A

Type Coercion.

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

var one, two, tree, result;
one = ‘1’;
two = 2;
three = 3;

what is the result of ‘one + two + three’?

A

‘123’

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

var one, two, tree, result;
one = ‘1’;
two = 2;
three = 3;

what is the result of ‘one + (two + three)’?

A

‘15’

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

In Javascript, why are we concatenating a string and a number, the result being a string?

A

This is because the number is being coerced into a string.

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

How does Javascript handle coercion?

A

Triple equals.

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

In Javascript, definining a variable without a value will result in what?

A

‘undefined’

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

In Javascript defining a variable with value of ‘null’ will result in what?

A

will resutl to an object (null is an object, where undefined is it’s own type)

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

What will undefined == null (double equals) return?

A

returns true

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

What will undefined === null (triple equals) result in? Why?

A

Returns false. No coercion is done on triple equals.