JavaScript Flashcards

1
Q

What is the purpose of variables?

A

To store data/information

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

How do you declare a variable?

A

declaring the variable and giving it a name

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 the ‘=’ (assignment operator) and giving it a 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

letters , $ , _ (underscore) , and numbers but can’t start with numbers

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

capital and lowercase letters affect the name. You can have variables spelled the same but with different capitalization

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

storing text / using any 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 store numbers for calculations / do math / represent numerical 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

it only has 2 values / used to determine what part of a script should run

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

Assignment operator / used to assign variables to data

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

What is the difference between null and undefined?

A

null is intentional / while undefined is something you didn’t calculate

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

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

A

so you know what you are logging

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

Give five examples of JavaScript primitives.

A

undefined, null, boolean, string, number

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

What data type is returned by an arithmetic operation?

A

number

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

What is string concatenation?

A

combining 2 or more strings

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

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

A

it is an arithmetic operator and you can use it with adding numbers / also concatenate strings

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

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

A

a boolean

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

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

A

it adds the value on the right to the left value

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

What are objects used for?

A

group together a set of variables and functions

combining like data (cars, person)

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

What are object properties?

A

variable that is part of an object

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

Describe object literal notation.

A

easiest way to create an object

variable declaration with name and assign it a value of {} with properties and methods inside

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

How do you remove a property from an object?

A

delete objectName followed by the property name

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

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

A

the dot notation and bracket notation

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

What are arrays used for?

A

to store a list of items / values

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

Describe array literal notation.

A

var name = [] / var variable with the name assignment operator with square brackets and properties inside

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
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
26
Q

What is the length property of an array?

A

property that tells you how long an array is

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

How do you calculate the last index of an array?

A

by subtracting 1 from the length

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

How are arrays different from “plain” objects?

A

they maintain order

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

What is a function in JavaScript?

A

a reusable line of code that can do multiple things

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

Describe the parts of a function definition.

A
function keyword to create the function
optional name
parenthesis with an parameter or if multiple separate with comma
start of the code block with {
optional return statement at the end
end of the code block with }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

Describe the parts of a function call.

A

name of the function with () and the argument/arguments inside

32
Q

When comparing them side-by-side, what are the differences between a function call and a function definition?

A

the function call is barebones in that it is only the name of the function and arguments

33
Q

What is the difference between a parameter and an argument?

A

arguments are the ones that go into calling the functions

parameters go in the function definition and are only placeholders

34
Q

Why are function parameters useful?

A

they are placeholders so you can input so you can input your own arguments and be able to use the functions multiple times

35
Q

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

A

Causes the function to produce a value we can use in our program.
Prevents any more code in the function’s code block from being run.

36
Q

Why do we log things to the console?

A

to be able to check if we are getting the return we want

37
Q

What is a method?

A

A JavaScript method is a property of an object that contains a function definition. Methods are functions stored as object properties.

38
Q

How is a method different from any other function?

A

A function is a block of code written to perform some specific set of tasks.
A JavaScript method is a property of an object that contains a function definition.

39
Q

How do you remove the last element from an array?

A

.pop() method

40
Q

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

A

Math.round()

41
Q

How do you generate a random number?

A

Math.random()

42
Q

How do you delete an element from an array?

A

.pop() , .shift() , .splice()

43
Q

How do you append an element to an array?

A

.push() , .unshift()

44
Q

How do you break a string up into an array?

A

.split()

45
Q

Do string methods change the original string? How would you check if you weren’t sure?

A

yes by console.log()

46
Q

Roughly how many string methods are there according to the MDN Web docs?

A

59 / alot

47
Q

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

A

no / you dont always need a return value

48
Q

Roughly how many array methods are there according to the MDN Web docs?

A

around 50

49
Q

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

A

mdn

50
Q

Give 6 examples of comparison operators.

A

== , === . > , < , <= , >=, !=

51
Q

What data type do comparison expressions evaluate to?

A

boolean

52
Q

What is the purpose of an if statement?

A

executes code only on specified conditions

53
Q

Is else required in order to use an if statement?

A

it is not

54
Q

Describe the syntax (structure) of an if statement.

A

if keyword (paranthesis) with conditions / curly brackets for code block beginning then what to return / last the closing code block }

55
Q

What are the three logical operators?

A

&& || ! (and or not)

56
Q

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

A

with && or || (and or or operators)

57
Q

What is the purpose of a loop?

A

to repeatedly use the same code until its condition is false / do something as fast as possible multiple times

58
Q

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

A

so it has an end point / and stops the code or it can crash your browser

59
Q

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

A

every time it goes through a loop / is an object which defines a sequence and potentially a return value upon its termination.

60
Q

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

A

starts after the first run / and after each run

61
Q

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

A

at the start of the loop / before it starts

62
Q

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

A

after the initialization expression

/ after the final expression

63
Q

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

A

after the condition is checked / after the work as well

64
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 keyword

65
Q

What does the ++ increment operator do?

A

adds 1 / reassigns to value

66
Q

How do you iterate through the keys of an object?

A

with a for… in loop

67
Q

What is Array.prototype.filter useful for?

A

when you want to get only some items from the array back.

68
Q

What is Array.prototype.map useful for?

A

returning a new and changing every element in the array. / lets us loop through an array and make changes and return to new array

69
Q

What is Array.prototype.reduce useful for?

A

to reduce the array down to one value.

70
Q

What is “syntax sugar”?

A

syntax that is designed to make code easier to read

71
Q

What is the typeof an ES6 class?

A

Function

72
Q

Describe ES6 class syntax.

A
keyword of class followed by the class name the {
constructor method (parameters){this.param=parameter}}
73
Q

What is “refactoring”?

A

is the process of restructuring existing computer code—changing the factoring—without changing its external behavior

74
Q

What does fetch() return?

A

A promise

75
Q

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

A

GET

76
Q

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

A

by adding a second argument to the fetch request as an object with a method property / IN ALL CAPS