Coercion Flashcards
Generally speaking, you’re most likely to find strongly typed languages where?
Within programming languages that are compiled.
Name a few compiled languages.
C and C++
Why is Java an exception?
Java is not necessarily compiled into binary executables but to bytecode that is interpreted by a third party piece of software.
What is another name for dynamically typed languages?
Weakly typed
What must you do in strongly typed languages for functions?
Denote the type of information a function will return. i.e. public boolean isAlive() { return true; }
Define Coercion.
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.
Difference between coercion and conversion.
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.
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?
Type Coercion.
var one, two, tree, result;
one = ‘1’;
two = 2;
three = 3;
what is the result of ‘one + two + three’?
‘123’
var one, two, tree, result;
one = ‘1’;
two = 2;
three = 3;
what is the result of ‘one + (two + three)’?
‘15’
In Javascript, why are we concatenating a string and a number, the result being a string?
This is because the number is being coerced into a string.
How does Javascript handle coercion?
Triple equals.
In Javascript, definining a variable without a value will result in what?
‘undefined’
In Javascript defining a variable with value of ‘null’ will result in what?
will resutl to an object (null is an object, where undefined is it’s own type)
What will undefined == null (double equals) return?
returns true