JavaScript Flashcards

1
Q

What is the purpose of variables?

A

To store/see data that came together from the past & preserve data to use in the future

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

How do you declare a variable?

A

By using let, const or var

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

How do you initialize (assign a value to) a variable?

A

By using the assignment operator to give it value

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

What characters are allowed in variable names?

A

Letter
Underscore
$
numbers (but it cannot be the first character)

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

What does it mean to say that variable names are “case sensitive”?

A

Capitalized and lowercase letters mean different things

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

What is the purpose of a string?

A

To store a series of characters

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

What is the purpose of a number?

A

To perform math

To represent numeric values

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

What is the purpose of a boolean?

A

To make decisions

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

What does the = operator mean in JavaScript?

A

To make it hold/contain a value

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

How do you update the value of a variable?

A

By assigning a new value

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

What is the difference between null and undefined?

A

Null is intentional absence/emptiness

Undefined means there is no value assigned

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

Why is it a good habit to include “labels” when you log values to the browser console?

A

To make it easy to know which value the console is printing

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

Give five examples of JavaScript primitives.

A
Boolean
Null
Number
String
Undefined 

(and BigInt and Symbol)

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

What data type is returned by an arithmetic operation?

A

Numeric/number

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

What is string concatenation?

A

To join/append strings

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

What purpose(s) does the + plus operator serve in JavaScript?

A

To add numbers or to concatenate strings

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

What data type is returned by comparing two values (x === x, etc)?

A

Boolean

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

What does the += “plus-equals” operator do?

A

Adds the value on the right side of the operator to the variable and assigns the result back to the variable

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

What are objects used for?

A

To group together a set of properties and methods

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

What are object properties?

A

Chunk of data attached to objects

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

Describe object literal notation

A

var variableName = {
key : value,
key : value
}

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

How do you remove a property from an object?

A

With the delete operator

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

What are the two ways to get or update the value of a property?

A

By using dot notation or square brackets

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

What are arrays used for?

A

For storing a list of values

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

Describe array literal notation

A

arrayname[‘value’, ‘value’];

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

How are arrays different from “plain” objects?

A

There is an order
They are numerically indexed
It keeps a count of the number of values in it

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

What number represents the first index of an array?

A

0

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

What is the length property of an array?

A

It’s a property that returns the number of values in that array

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

How do you calculate the last index of an array?

A

arrayName.length - 1

30
Q

What is a function in JavaScript?

A

Reusable block of code

31
Q

Describe the parts of a function definition.

A
function optName(parameters) {
     block of code to run
     optional return keyword
};
32
Q

Describe the parts of a function call:

A

functionName( );

33
Q

When comparing them side-by-side, what are the differences between:

a function call
vs
a function definition?

A
  • No function keyword

- No curly braces and code block

34
Q

What is the difference between a parameter and an argument?

A

Parameter is a placeholder name

Argument is the value that actually gets passed

35
Q

Why are function parameters useful?

A

They give us an idea of what kind of value were looking to put in the argument

36
Q

What two effects does a return statement have on the behavior of a function?

A
  1. Produces a value

2. Ends the code block from running

37
Q

Why do we log things to the console?

A
  • To see change over time

- As a debugging mechanism

38
Q

What is a method?

A

Function stored in a property

function that is the property of an object

39
Q

How is a method different from any other function?

A

They are attached to objects (so you have to specify the object name)

40
Q

How do you remove the last element from an array?

A

.pop()

41
Q

How do you round a number down to the nearest integer?

A

Math.floor()

42
Q

How do you generate a random number?

A

Math.random()

43
Q

How do you delete an element from an array?

A

.splice(index, how many items to remove)

44
Q

How do you append (add to end) an element to an array?

A

.push()

45
Q

How do you break a string up into an array?

A

.split()

46
Q

Do string methods change the original string?

How would you check if you weren’t sure?

A

No (strings are immutable)

console.log()

47
Q

Is the return value of a function or method useful in every situation?

A

No because sometimes you’re interested in simply what the function/method does and not its return value

48
Q

What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?

A

MDN

49
Q

Give 6 examples of comparison operators

A
==
===
!=
!==
<
><=
>=
50
Q

What data type do comparison expressions evaluate to?

A

Boolean

51
Q

What is the purpose of an if statement?

A

Make a decision on which code block to run depending on the Boolean result

52
Q

Is else required in order to use an if statement?

A

No – you don’t always need an alternative

53
Q

Describe the syntax (structure) of an if statement.

A
if (condition) {
   statement1;
} else {  
   statement2;
}
54
Q

What are the three logical operators?

A

&& (and)
|| (or)
! (not)

55
Q

How do you compare two different expressions in the same condition?

A

By using logical operators && or ||

56
Q

What is the purpose of a loop?

A

To keep executing a code as long as a condition runs true

57
Q

What is the purpose of a condition expression in a loop?

A

To let the function know when to end

58
Q

What does “iteration” mean in the context of loops?

A

One execution of code block

59
Q

When does the condition expression of a while loop get evaluated?

A

In the beginning before the code block executes

60
Q

When does the initialization expression of a for loop get evaluated?

A

In the beginning before anything

61
Q

When does the condition expression of a for loop get evaluated?

A

Before each iteration

62
Q

When does the final expression of a for loop get evaluated?

A

After the code block is executed

63
Q

Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?

A

break

64
Q

What does the ++ increment operator do?

A

adds 1 to value

65
Q

How do you iterate through the keys of an object?

A

for…in loop

66
Q

What must the return value of myFunction be if the following expression is possible?

myFunction()();

A

A function!

myFunction is being called and the return is being called immediately

67
Q

What does this code do?

const wrap = value => () => value;

A

Defines a function that defines the value and defines another function that returns that value

68
Q

In JavaScript, when is a function’s scope determined; when it is called or when it is defined?

A

Defined

69
Q

What allows JavaScript functions to “remember” values from their surroundings?

A

Closures

70
Q

What does fetch() return?

A

A Promise

If you get back a promise what do you do with it? You can call .then OR .catch on it

71
Q

What is the default request method used by fetch()?

A

GET

72
Q

How do you specify the request method (GET, POST, etc.) when calling fetch?

A

fetch(‘string of resource’, { method: ‘GET’ })