JavaScript Flashcards

1
Q

What is the purpose of variables?

A

to hold data that can used or referenced later

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

How do you declare a variable?

A

use the keywords var, const, and let and then the variable 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

use the assignment operator =

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, $, _ , and numbers but numbers 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

var number and var Number are two different variables

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 and manipulate text

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

math, quantities, count things

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

true or false values, booleans exist for decision making. this or that

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. giving value to a variable

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

refer to the variable again and give it 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

both carry empty values, but null is intentionally assigned - it’s organic. undefined is inorganic. it comes from JavaScript. Baked into the language.

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

it will give us a point of reference

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, boolean, undefined, and null

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

number

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

What is string concatenation?

A

combining two or more string values

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

adds numbers and concatenates 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 (<a>«/a>, <a>></a>, ===, etc)?</a>

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

take current value and addon whatever we stated and the result of that expression if the new value of 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

area to store data under one hood so everything is easier to access

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

What are object properties?

A

variables of the object

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

Describe object literal notation.

A

{
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

delete keyword

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

dot notation or bracket notation

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

What are arrays used for?

A

to store values with order

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

Describe array literal notation.

A
var example = [
  'thing1',
  thing2,
  thing3
];
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 have order, indexes are not individually named, will repair themselves if an index is deleted, have a set length

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

stores the total amount of stuff 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

subtract by 1 from the length property

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 set of statements to perform a task that can help you repeat a certain task

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
function name-of-function(parameter) {
  \_\_\_;
  return \_\_\_\_;
}
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

name of function, (), and arguments if need be

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

function call - actual values are being passed in

function definition - curly braces, a code block, function keyword

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

parameter - placeholder value

argument - the actual value

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

Why are function parameters useful?

A

without parameters, functions would always do the exact same thing, as in give the exact same result every time and the function can’t apply for other instances. ADAPTABILITY

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

returns a result and ends the function

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

Why do we log things to the console?

A

so we know if there are any errors in our code at any given time

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

What is a method?

A

function that’s a property of an object

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

How is a method different from any other function?

A

methods have to say where they’re coming from

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

How do you remove the last element from an array?

A

pop()

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

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

A

Math.floor()

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

How do you generate a random number?

A

Math.random()

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

How do you delete an element from an array?

A

shift(), pop(), splice()

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

How do you append an element to an array?

A

push()

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

How do you break a string up into an array?

A

split()

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

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

A

no. console log it or MDN

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

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

A

A lot

48
Q

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

A

no

49
Q

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

A

a lot

50
Q

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

A

mdn

51
Q

Give 6 examples of comparison operators.

A

===, <a>«/a>, <a>></a>, <a>«/a>=, <a>></a>=, !==</a></a>

52
Q

What data type do comparison expressions evaluate to?

A

booleans

53
Q

What is the purpose of an if statement?

A

you’re checking a certain condition and if it passes the criteria, do something

54
Q

Is else required in order to use an if statement?

A

no

55
Q

Describe the syntax (structure) of an if statement.

A

if (condition) {
code here
}

56
Q

What are the three logical operators?

A

||, &&, !

57
Q

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

A

use the logical operators

58
Q

What is the purpose of a loop?

A

to do something over and over again until a certain point

59
Q

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

A

use the condition to continue a task or stop

60
Q

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

A

passing through the code block

61
Q

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

A

beginning and before each iteration

62
Q

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

A

beginning. happens only once

63
Q

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

A

before each iteration

64
Q

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

A

at the end of each iteration

65
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

66
Q

What does the ++ increment operator do?

A

increments the variable by one

67
Q

How do you iterate through the keys of an object?

A

for in loop

68
Q

What event is fired when a user places their cursor in a form control?

A

focus

69
Q

What event is fired when a user’s cursor leaves a form control?

A

blur

70
Q

What event is fired as a user changes the value of a form control?

A

input

71
Q

What event is fired when a user clicks the “submit” button within a ?

A

submit

72
Q

What does the event.preventDefault() method do?

A

Prevents the browser from automatically reloading with the forms values in the URL/prevents default behavior of the form

73
Q

What does submitting a form without event.preventDefault() do?

A

Automatically load the form values.

74
Q

What property of a form element object contains all of the form’s controls.

A

elements property

75
Q

What property of form a control object gets and sets its value?

A

value

76
Q

What is one risk of writing a lot of code without checking to see if it works so far?

A

code could be broken and you have no idea where it broke

77
Q

What is an advantage of having your console open when writing a JavaScript program?

A

know immediately when your program runs into an error

78
Q

What is JSON?

A

JavaScript Object Notation. data exchange format that contains a string

79
Q

What are serialization and deserialization?

A

serial - convert object into string so it can be transferrable
deserial - convert bytes into stream of data

80
Q

Why are serialization and deserialization useful?

A

you can send objects over a network and it can be parsed by the receiver.
serialization makes it easier + more efficient to send data
deserialization is reading that data

81
Q

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

A

JSON.stringify

82
Q

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

A

JSON.parse

83
Q

How to you store data in localStorage?

A

setItem

84
Q

How to you retrieve data from localStorage?

A

getItem

85
Q

What data type can localStorage save in the browser?

A

strings

86
Q

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

A

before the page/tab closes/unloads

87
Q

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

A

a method definition has a code block. a method call is just the method name and ()

88
Q

Describe method definition syntax (structure).

A

methodName (parameter) {}

89
Q

Describe method call syntax (structure).

A

methodName()

90
Q

How is a method different from any other function?

A

method is a property of an object. still a function though

91
Q

What is the defining characteristic of Object-Oriented Programming?

A

objects can contain both data (as properties) and behavior (as methods).

92
Q

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

A

Abstraction
Encapsulation
Inheritance
Polymorphism

93
Q

What is “abstraction”?

A

being able to work with (possibly) complex things in simple ways

94
Q

What does API stand for?

A

It is a type of software interface, offering a service to other pieces of software

95
Q

What is the purpose of an API?

A

give programmers a way to interact with a system in a simplified, consistent fashion: aka, an abstraction

96
Q

What is this in JavaScript?

A

this is an implicit parameter of all JavaScript functions

97
Q

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

A

Its available in a function code block even though it was never included in the functions parameter

98
Q

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

A

call time

99
Q
What does this refer to in the following code snippet?
var character = {
  firstName: 'Mario',
  greet: function () {
    var message = 'It\'s-a-me, ' + this.firstName + '!';
    console.log(message);
  }
};
A

nothing. this is determined at call time not definition

100
Q

Given the above character object, what is the result of the following code snippet? Why?
character.greet();

A

It’s a me, Mario

101
Q
Given the above character object, what is the result of the following code snippet? Why?
var hello = character.greet;
hello();
A

it’s a me, undefined
it’s just the anon function that is being assigned to hello. the anon function is being “detached” from the character object. hello is attached to the window. window does not have a firstName property thus giving you undefined.

102
Q

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

A

You can’t

103
Q

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

A

left of the dot .

if there’s no dot, then window by default

104
Q

What kind of inheritance does the JavaScript programming language use?

A

prototypal inhertiance

105
Q

What is a prototype in JavaScript?

A

object that contains properties and (predominantly) methods that can be used by other objects

106
Q

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

A

__proto__ object

107
Q

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

A

its placed in a prototype object and then the objects will delegate to that object when they aren’t able to perform the required tasks themselves.

108
Q

What does the new operator do?

A

lets developers create an instance of a user-defined object type or of one of the built-in object types that has a constructor function.

109
Q

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

A

prototype property

110
Q

What does the instanceof operator do?

A

tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object.

111
Q

What is a “callback” function?

A

a function that’s being passed around like a value

112
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

setTimeout()

113
Q

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

A

setInterval()

114
Q

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

A

0 - immediately

115
Q

What do setTimeout() and setInterval() return?

A

interval id which is an integer