Main deck Flashcards

1
Q

What are “var, let, const”?

A

Declaration Keywords

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

What does var do?

A

Declares a variable of global scope

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

What does let do?

A

Declares a variable of block scope

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

What does const do?

A

Declares a variable that cannot be reassigned.

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

What does it mean to “declare a variable”?

A

It means telling the computer to open a slot in memory where it can place a value in the future.

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

What can be stored in a variable?

A

Any “value” - numbers, strings, booleans, objects, etc.

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

What are the 5 basic (or “primitive”) data types?

A

Number, string, boolean, undefined, null

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

What’s the difference between ‘5’ and 5?

A

The first one is a string and the second one is a number.

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

What does var x = 5 do?

A

Declares a variable called x and assigns the value 5 to it.

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

Are semicolons required in javascript?

A

No but it’s a good idea to use them.

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

What should the file extension be for a javascript file?

A

.js

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

How do you get to a javascript console in terminal?

A

node

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

What are the boolean values?

A

true and false

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

What does (5+2) resolve to?

A

10

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

What is the operator = called?

A

The assignment operator

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

What does the operator = do?

A

Assigns the value on the right to the variable on the left.

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

What are all these called: =, +, -, ==, %, !, !=

A

Operators

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

What category of operators are all these: ==, &&;&&;, ||, !=

A

Boolean operators

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

What is the operator == called?

A

The comparison operator

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

What does the operator == do?

A

Compares both sides and returns true if they are equal (but not necessarily the same type).

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

What is the operator === called?

A

“True equals” or “strict comparison” operator.

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

What does the operator === do?

A

Compares both sides and returns true if they are equal (AND the same type!).

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

What does the operator != do?

A

Returns true if the two sides are NOT equal.

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

What is the operator ! called?

A

The negation operator (often called “NOT”).

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

What does the operator ! do?

A

Flips (“negates”) the boolean value…true turns to false and false turns to true.

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

What does !!true && true resolve to?

A

true

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

What does !(true || false) && !(true && false) resolve to?

A

false

28
Q

How are parentheses used in programming?

A

Just like in math - they tell the computer to resolve everything inside the parentheses before doing anything else.

29
Q

Are you required to assign a value to a variable when you declare it?

A

No - you can write var x and that will declare the variable and the value will be undefined.

30
Q

What value does a variable have before you assign a value to it?

A

undefined

31
Q

What’s the difference between var and let?

A

var gives you a variable with global scope and let gives you a variable with block scope

32
Q

What does it mean if a variable has global scope?

A

The variable can be used anywhere in the file.

33
Q

What does it mean if a variable has block scope?

A

The variable can only be used inside the block where it is declared.

34
Q

What is a “block”?

A

Code that is surrounded by { and } (curly braces)

35
Q

What is the operator % called?

A

Modulus

36
Q

What does the operator % do?

A

Computes the remainder of the number on the left when you divide it by the number on the right.

37
Q

What does the operator >= do?

A

Returns true if the number on the left is greater than or equal to the number on the right.

38
Q

What does "5"+10 resolve to?

A

510 (it converts the number 10 to string “10” before adding - this is called type coercion)

39
Q

What are two names for the following code: if (...) {... }

A

“If statement” and “conditional statement”

40
Q

What does syntax mean?

A

Syntax means the way something is written in code.

41
Q

What is the syntax for a conditional/if statement?

A

if (condition) {

}

42
Q

What is the stuff inside the parentheses in an if statement called?

A

The condition

43
Q

What does an if statement do?

A

Tells the computer to only execute the code inside the block if the condition is true.

44
Q
What will be logged on the console for the following code?
let x = 5;
if (x == 5) {
    console.log('marko is a boss');
} else {
    console.log('raymond is a boss');
}
A

marko is a boss

45
Q
What will be logged on the console for the following code?
let x = 5;
if (x >=  6 || x <= 4) {
    console.log('marko is a boss');
} else {
    console.log('raymond is a boss');
}
A

raymond is a boss

46
Q

In a conditional statement, when is an “else if” block of code executed?

A

If the first condition was false but the condition after “else if” was true.

47
Q

In a conditional statement, when is an “else” block of code executed?

A

When the condition was false.

48
Q

What is the syntax of a for loop?

A

for (iterator declaration; iterator condition; iterator mutation) {
….
}

49
Q

In a for loop, you always declare a variable right after the for keyword. What is that variable called in general?

A

The iterator

50
Q

What does it mean to “iterate” over an array?

A

To loop through the values of the array with a for loop.

51
Q

What is an object?

A

A collection of properties grouped together in one variable name.

52
Q

What is the syntax to declare a variable and assign an empty object to it?

A

let myObject = {};

53
Q

What is the syntax for accessing a property called “color” in an object called “paint”?

A

paint.color or paint[‘color’] (notice the quotes in the second one)

54
Q

Suppose you declare an object let x = {color:'green', size:10};. What are “color” and “size” called?

A

Keys or properties

55
Q

Suppose you declare an object let x = {color:'green', size:10};. What are “color” and “size” called?

A

Values

56
Q

What is an array?

A

A list of values grouped together in one variable name.

57
Q

Suppose you declare an array let myArray = [1,2,3]. What does myArray[1] resolve to?

A

2 (because the index starts at zero)

58
Q

Suppose you have an array called myArray. In the code myArray[6], what is the stuff inside the square brackets called?

A

The index

59
Q

When you have a variable or object called myObject, using the . (dot) operator allows you to…

A

access any of the object’s properties or methods.

60
Q

What is a method?

A

A function attached to an object or variable.

61
Q

What is a function?

A

A block of code that you can reuse by replacing the arguments with any value you want.

62
Q

Does a function have to have arguments?

A

No

63
Q

Does a function have to return something?

A

No

64
Q

If a function accepts something as input, the input(s) are called…

A

argument(s)

65
Q

How does a method differ from a function?

A

A method is just a function that is attached to a variable, so it does something with the variable it is attached to.