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
What does the operator `!` do?
Flips ("negates") the boolean value...true turns to false and false turns to true.
26
What does `!!true && true` resolve to?
true
27
What does `!(true || false) && !(true && false)` resolve to?
false
28
How are parentheses used in programming?
Just like in math - they tell the computer to resolve everything inside the parentheses before doing anything else.
29
Are you required to assign a value to a variable when you declare it?
No - you can write `var x` and that will declare the variable and the value will be undefined.
30
What value does a variable have before you assign a value to it?
undefined
31
What's the difference between var and let?
var gives you a variable with global scope and let gives you a variable with block scope
32
What does it mean if a variable has global scope?
The variable can be used anywhere in the file.
33
What does it mean if a variable has block scope?
The variable can only be used inside the block where it is declared.
34
What is a "block"?
Code that is surrounded by { and } (curly braces)
35
What is the operator `%` called?
Modulus
36
What does the operator `%` do?
Computes the remainder of the number on the left when you divide it by the number on the right.
37
What does the operator `>=` do?
Returns true if the number on the left is greater than or equal to the number on the right.
38
What does `"5"+10` resolve to?
`510` (it converts the number 10 to string "10" before adding - this is called type coercion)
39
What are two names for the following code: `if (...) {... }`
"If statement" and "conditional statement"
40
What does syntax mean?
Syntax means the way something is written in code.
41
What is the syntax for a conditional/if statement?
if (condition) { ... }
42
What is the stuff inside the parentheses in an if statement called?
The condition
43
What does an if statement do?
Tells the computer to only execute the code inside the block if the condition is true.
44
``` 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'); } ```
marko is a boss
45
``` 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'); } ```
raymond is a boss
46
In a conditional statement, when is an "else if" block of code executed?
If the first condition was false but the condition after "else if" was true.
47
In a conditional statement, when is an "else" block of code executed?
When the condition was false.
48
What is the syntax of a for loop?
for (iterator declaration; iterator condition; iterator mutation) { .... }
49
In a for loop, you always declare a variable right after the `for` keyword. What is that variable called in general?
The iterator
50
What does it mean to "iterate" over an array?
To loop through the values of the array with a for loop.
51
What is an object?
A collection of properties grouped together in one variable name.
52
What is the syntax to declare a variable and assign an empty object to it?
let myObject = {};
53
What is the syntax for accessing a property called "color" in an object called "paint"?
paint.color or paint['color'] (notice the quotes in the second one)
54
Suppose you declare an object `let x = {color:'green', size:10};`. What are "color" and "size" called?
Keys or properties
55
Suppose you declare an object `let x = {color:'green', size:10};`. What are "color" and "size" called?
Values
56
What is an array?
A list of values grouped together in one variable name.
57
Suppose you declare an array `let myArray = [1,2,3]`. What does `myArray[1]` resolve to?
2 (because the index starts at zero)
58
Suppose you have an array called myArray. In the code `myArray[6]`, what is the stuff inside the square brackets called?
The index
59
When you have a variable or object called myObject, using the `.` (dot) operator allows you to...
access any of the object's properties or methods.
60
What is a method?
A function attached to an object or variable.
61
What is a function?
A block of code that you can reuse by replacing the arguments with any value you want.
62
Does a function have to have arguments?
No
63
Does a function have to return something?
No
64
If a function accepts something as input, the input(s) are called...
argument(s)
65
How does a method differ from a function?
A method is just a function that is attached to a variable, so it does something with the variable it is attached to.