The JavaScript Universe Flashcards

1
Q

What are values in JS?

A

Values are: booleans, numbers, strings, symbols, functions and objects, null and undefined.

Things like if statements, loops and variable declarations aren’t values.

MDN defines JS objects as follows:

The set of types in the JavaScript language consists of primitive values and objects.

Primitive values (immutable datum represented directly at the lowest level of the language)

Boolean type
Null type
Undefined type
Number type
BigInt type
String type
Symbol type

and

Objects (collections of properties)

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

Are values in our code?

A

No, values are not ‘in our code’. They exist in the runtime. Our code interacts with values rather than being comprised of values.

Like the little prince looking up at the night sky, we might refer to those stars but those stars aren’t ours. We might refer to the values but they aren’t in our code.

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

What does it mean to ‘give it 5 minutes’?

A

Essentially it’s to think rather than react - give ideas 5 minutes to sink in, give them the time of day before denouncing them.

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

What are the two different types of values in javascript?

A

Primitive values and ‘objects and functions’.

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

What is a primitive value?

A

Like cold, distant stars - primitives exist outside the code but we’re able to point to them. Examples of primitives are numbers like 2 and strings like “poop”.

Importantly you can’t touch or manipulate stars. They can’t be created by us and are permanent, unchanging and untouchable.

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

What is a non-primitive value?

A

Like asteroids in orbit we can access these values and manipulate them. They’re not part of your world (code) but they’re close enough to manipulate.

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

What are functions?

A

Functions are really just objects with a few additional features.

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

List all 9 different types of values in JS.

A

String, Boolean, Number, Object, Function, Null, Undefined, BigInt, Symbol

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

What is the common use case for undefined vs null?

A

Null is used to explicitly set missing value.

Undefined is used for unintentionally missing values.

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

List all primitive values.

A

Number, String, Boolean, Null, Undefined, BigInt, Symbol

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

What are two of the most common non-primitive values?

A

Objects and Functions.

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

In JS, is everything an object?

A

Nope. Primitives might behave like objects ( “hi”.toUpperCase() ) but that’s just an illusion.

The JS engine creates a temporary object for this.

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

In JS, are functions objects?

A

Yes.

Functions are just objects with special, built-in methods and properties.

Functions are not just any old objects, they are Function objects, meaning that besides being able to assign properties and methods to them, they also have properties and methods already defined by the built-in Function object.

Functions share many characteristics with objects. But what distinguishes them is the fact that they can be ‘called’.

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

What is a good mental model for typeof?

A

A telescope - used to identify what X is floating around our little moon.

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

What is the correct name for labeling the following:

> 2 + 2
typeof(foo)

A

Expression.

Expressions are questions that JavaScript can answer. JavaScript answers expressions in the only way it knows how—with values.

Expressions always result in a single value.

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

Are arrays objects?

A

Yes!

17
Q

What happens if you typeof null?

A

You get an object! It’s lying. Null is not an object. Null is a primitive.

Null has never had its type corrected since it would break a lot of the internet which relies on this historical quirk.

JS was written very fast (10 days) and he missed this bug.

18
Q

What will typeof(typeof(2)) return?

A

string