JavaScript Flashcards

1
Q

What is the purpose of variables?

A

helps store data to remember

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

How do you declare a variable?

A

var declares/makes the variable

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

you assign it with a = sign.

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(can be used as long as it’s not 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

if you accidentally capitalize a letter it is a WHOLE DIFFERENT VARIABLE.

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

it’s a way to hold a sequence of variables

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 do math

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

a true or false statement

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

an assignment

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

no keyword is necessary (something = ‘something’)

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 a value that can only be assigned. undefined can come from many different things.

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

if you console.log without a label you don’t know what it really is.

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

Give five examples of JavaScript primitives.

A

string, number, undefined, null, and boolean.

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

a number

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

What is string concatenation?

A

adding strings together to make a bigger string

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

addition or concateanation.

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

What data type is returned by comparing the two values (<, >, ===, 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 variable

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

What are objects used for?

A

They group together a set of variables and functions.

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

What are object properties?

A

variables that are apart of an object.

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

Describe object literal notation.

A

{
something: value,
something2: value2,
}

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

You use the keyword delete and then use dot notation to identify the property or method you want to get rid of.

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

var varName = object.property/method name
OR
object.propertyname = “property value”

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

What are arrays used for?

A

good for rendering lists of data that are important or not important.

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

Describe array literal notation.

A

variable followed by a name followed by bracket notation followed by strings, or a list of items.

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

Arrays are a special type of variable that is also mutable and can also be used to store a list of values.

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 tells you how many properties you have in the 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

you subtract the length of the array by one and then assign it to a new variable.

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

What is a function in Javascript?

A

a chunk of code that returns something.

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

Describe the parts of a function definition.

A
  1. function keyword. 2. optional name. 3. a list of parameters.
  2. opening curly brace. 5. optional return. 6. closing curly brace.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

Describe the parts of a function call.

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

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

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

What is the difference between a parameter and an argument?

A

putting things in the ()

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

Why are function parameters useful?

A

They allow for the function to take in values. if they weren’t there. functions would do the same thing over and over again.

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

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

A

return spits out a value that the rest of the coed can use. Anything under the return statement WILL NOT RUN.

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

Give 6 examples of comparison operators.

A

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

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

What data type do comparison expressions evaluate too?

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

What is the purpose of an if statement?

A

to provide an output of true or false.

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

Is else required in order to use an if statement?

A

no.

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

Describe the syntax (structure) of an if statement.

A
42
Q

What are three logical operators?

A

logical and, logical or, logical not. &&, ||, !

43
Q

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

A
44
Q

Why do we log things in the console?

A

to debug certain parts of our code.

45
Q

What is a method?

A

a method is a function which is a property of an object. a method could also be considered an object reference to a function.

46
Q

How is a method different from any other function?

A

methods are attributed to an object.

47
Q

How do you remove the last element from an array?

A

.pop() method

48
Q

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

A

Math.floor() method

49
Q

How do you generate a random number?

A

Math.random() method.

50
Q

How do you delete an element from an array?

A

.splice() method

51
Q

How do you append an element to an array?

A

.push() method

52
Q

How do you break a string up into an array?

A

.split() method

53
Q

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

A

it doesn’t change the string and you can console.log it.

54
Q

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

A

no.

55
Q

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

A

MDN

56
Q

What is the purpose of a loop?

A

it is a way for a function code block to keep running until it meets it requirements

57
Q

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

A

it’s what stops the loop from running infinitely.

58
Q

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

A

iteration is the amount of times that the loop runs.

59
Q

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

A

before each iteration.

60
Q

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

A

only in the beginning and it gets checked just once.

61
Q

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

A

it happens after the initialization and then checks the condition every time before it runs the code block

62
Q

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

A

after each iteration.

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

it increases the value by 1.

65
Q

How do you iterate through the keys of an object?

A
66
Q

What is JSON?

A
67
Q

What are serialization and deserialization?

A

converts our object into a string and deserialization is the opposite of it.

68
Q

Why serialization and deserialization useful?

A

serialization is easy to store data for later. deserialization is easy to organize and reuse data.

69
Q

How do you serialize a data structure into a JSON string using JavaScript?

A

JSON.stringify()

70
Q

How do you deserialize a JSON string into a data structure using Javascript?

A
71
Q

How do you store data in localStorage?

A
72
Q

How do you retrieve data from localStorage?

A
73
Q

What data type can localStorage save in the browser?

A
74
Q

When does the ‘beforeunload’ event fire on the window object?

A
75
Q

What is a method?

A

A method is a function which is a property of an object.

76
Q

How can you tell the difference between a method definition and a method call?

A

the method definition consists of a method header and method body while the method call method.name();

77
Q

Describe method definition syntax (structure).

A

property: function () {
method body;
};

78
Q

Describe method call syntax (structure).

A

method.name(arguements);

79
Q

How is a method different from any other function?

A

the method had to be associated with an object while a function isn’t.

80
Q

What is the defining characteristic of Object-Oriented Programming?

A

Encapsulation. (all important information is contained inside an object and only select information is exposed.

81
Q

What are the four “principles” of Object-Oriented Programming?

A

Abstraction, encapsulation, polymorphism, and inheritance.

82
Q

What is “abstraction”?

A

hiding all but the relevant data about an object in order to reduce complexity and increase efficiency.

83
Q

What does API stand for?

A

Application programming interface.

84
Q

What is the purpose of an API?

A

API is a way for two or more computers to communicate with each other.

85
Q

What is .this in javascript?

A

refers to an object, and depends on how it’s being invoked(used or called). it refers to different objects when being used.

86
Q

What does it mean to say that this is an “implicit parameter”?

A

it is available in the functions code block even though it was never included in the function’s parameter list or declared with var.

87
Q

When is the value of this determined in a function; call time or definition time?

A

call time.

88
Q

How can you tell what the value of this will be for a particular function or method definition?

A

can only know if it’s being called.

89
Q

How can you tell what the value of this is for a particular function or method call?

A

what object is left to the dot. otherwise it is just window.

90
Q

What kind of inheritance does the JavaScript programming language use?

A

prototype

91
Q

What is a prototype in JavaScript?

A

object that shares data

92
Q

How is it possible to call methods on strings, arrays, and numbers even though those methods don’t actually exist on strings, arrays, and numbers?

A

it’s within the prototype method.

93
Q

If an object does not have its own property or method by a given key, where does JavaScript look for it?

A

prototype.

94
Q

What does the new operator do?

A

the new operator makes a blank javascript object from scratch it then takes the value of the prototype property and it makes it equal to the __prototype operator. the return is the new object if there is one.

95
Q

What property of JavaScript functions can store shared behavior for instances created with new?

A
96
Q

What does the instanceof operator do?

A

the instanceof operator tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object. The return value is a boolean value.

97
Q

What is a “callback” function?

A

a function that is passed into another function as an argument.

98
Q

Besides adding an event listener callback function to an element or the document, what is one way to delay the execution of a Javascript function until some point in the future?

A

you can use setTimeout()

99
Q

How can you setup a function to be called repeatedly without using a loop?

A

setInterval()

100
Q

What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?

A

0

101
Q

What setTimeout() and setInterval() return?

A