Section 3: Types and Operators Flashcards

1
Q

Dynamic typing

A

You don’t tell the javascript engine what type of data a variable holds, the engine figures it out while your code is running/executing.

Variables can hold different types of values because it’s all figured out during execution. (“figuring things out on the fly”)

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

Static typing

A

You tell the engine/compiler ahead of time what kind of data you intend to hold inside of a variable.

This is NOT what the javascript engine does. Javascript is dynamically typed, there is no keyword that tells the engine what kind of data you intend to put inside of the variable.

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

Primitive type

A

A type of data that represents a single value. That is, not an object.

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

undefined

A

A primitive type. undefined represents lack of existence (you shouldn’t set a variable to this)

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

null

A

A primitive type. null represents lack of existence (you CAN set a variable to this…leave undefined to the javascript engine)

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

boolean

A

A primitive type. true or false

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

number

A

A primitive type. This is the only numeric type in javascript and it is a floating point number (there’s always some decimals).

Unlike other programming languages, there’s only one ‘number’ type… and it can make math weird.

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

string

A

A primitive type. A sequence of characters (both ‘’ and “” can be used)

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

symbol

A

A primitive type. Used in ES6 (next version of Javascript). Not fully supported as of Q4 2015.

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

operator

A

A special function that is syntactically (written) differently.

Generally, operators take TWO parameters and return ONE result.

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

infix notation

A

operator sits between two parameters (as opposed to prefix notation)

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

Operator Precedence

A

Which operator function gets called first.

Functions are called in order of precedence (HIGHER precedence wins.)

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

[Operator] Associativity

A

What order operator functions get called in: left-to-right OR right-to-left.

Note: When functions have the SAME PRECEDENCE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
var a = 2, b = 3, c = 4;
a = b = c;
console.log(a);
console.log(b);
console.log(c);

What is logged in the console?

A

4
4
4

Assignment operator (=) has a precedence of 3 and its associativity is right-to-left (aka right associative)

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

Coercion

A

Converting a value from one type to another.

This happens quite often in Javascript because it’s dynamically typed.

var a = 1 + ‘2’; returns string ‘12’ because 1 is coerced into being a string representation of integer 1.

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

What does Number(undefined) return?

A

NaN

17
Q

What does Number(null) return?

A

0

18
Q

True or False: null coerces to 0 for comparison ( == )

A

False. Null does not coerce to 0 for comparison.

19
Q

True or false:

Does strict equality ( === ) coerce values?

A

False. Strict equality does not coerce values in the way that equality ( == ) will.

20
Q

In an if() statement, what is the javascript engine trying to convert the condition in parens to?

A

A boolean (true or false)

21
Q

What does the following return?

false || true

A

True

22
Q

What does this return when the function greet() is called?

function greet(name) { console.log('Hello ' + name); }
greet();
A

Hello undefined

23
Q

What does this return:

function greet(name) { name = name || ‘; console.log(‘Hello ‘ + name; }

greet(‘Tony’);
greet(0);
greet();

A

Hello Tony
Hello
Hello

24
Q

What is this code doing?

window.libraryName = window.libraryName || “Lib 2”;

A

It’s checking the window object - the global execution context/object - for any variable already named libraryName and if not, using the || operator, var libraryName is being give the value “Lib 2”