Eloquent.js Flashcards

1
Q

Basic types of values

A

numbers, strings, Booleans, objects, functions, and undefined values

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

What is an Expression?

A

An expression is any valid unit of code that resolves to a value. Think of it as a fragment of a sentence.

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

What is the environment?

A

The collection of variables and their values that exist at a given time.

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

Executing a function is called…

A

invoking, calling, or applying

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

What is a function?

A

A function is an assignment that JavaScript can take care of for you. It is a technique used to isolate a group of instructional code so that other parts of the application can depend on it to provide them with a reliable result. There are two main categories of functions you will be using in JavaScript: those that have already been created for you and those you create in your code.

An example of the former is alert().

Functions are the bread and butter of JavaScript programming. The concept of wrapping a piece of program in a value has many uses. It is a tool to structure larger programs, to reduce repetition, to associate names with subprograms, and to isolate these subprograms from each other.

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

What is a block?

A

A sequence of statements wrapped in braces. { }

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

What does “return” do inside a function?

A

A return statement determines the value the function returns. When control comes across such a statement, it immediately jumps out of the current function and gives the returned value to the code that called the function. The return keyword without an expression after it will cause the function to return undefined.

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

What is a “closure?”

A

A closure is a special kind of object that combines two things: a function, and the environment in which that function was created. The environment consists of any local variables that were in-scope at the time that the closure was created.

A closure lets you associate some data (the environment) with a function that operates on that data.

You can use a closure anywhere that you might normally use an object with only a single method.

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

Why isn’t the initialization hoisted?

A

Because that could affect the value of the variable during code execution and lead to unexpected results.

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

What does “mutable” mean?

A

Mutable is a type of variable that can be changed. In JavaScript, only objects and arrays are mutable, not primitive values.

(You can make a variable name point to a new value, but the previous value is still held in memory. Hence the need for garbage collection.)

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

What does “immutable” mean?

A

An immutable object is one whose content cannot be changed.
An object can be immutable for various reasons, for example:

To improve performance (no planning for the object's future changes)
To reduce memory use (make object references instead of cloning the whole object)
Thread-safety (multiple threads can reference the same object without interfering with one other)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are “higher-order” functions?

A

Functions that operate on other functions, either by taking them as arguments or by returning them, are called higher-order functions.

They come in several forms. For example, you can have functions that create new functions. You can have functions that change other functions. You can even write functions that provide new types of control flow.

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