JavaScript Flashcards

1
Q

What is the purpose of variables?

A

to be able to store and reference data

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 keyword var with its 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 =

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

anything but cannot start with a number or a be a keyword

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 letters are not the same as lowercase letters

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 words into javascript

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

used for counting and arithmetic

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 state yes or no within javascript

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

assign to

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

use the assign to and 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 empty on purpose. Undefined is nothing is defined (usually accident)

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

So console can be organized and easier to read

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, Null, Underfined

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

combining 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

add or concatenation

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 (, ===, 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

take the variable and update value

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

What are objects used for?

A

a box to keep related stuff together

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

What are object properties?

A

exclusive variables for an object

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

Use the delete operator (ex: delete person.firstName)

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

dot notation or with brackets

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

What is a function in JavaScript?

A

group of actions that are repeatable

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

Describe the parts of a function definition.

A

keyword function, function name, ( ) with parameaters if there are any, { }, return

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

Describe the parts of a function call.

A

the function name with ( ) including paramethers inside, if any

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

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

A

definition has keyword function and { }, calling does not

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

What is the difference between a parameter and an argument?

A

parameter are a placeholder until arguments are sent in

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

Why are function parameters useful?

A

allows us to change the value of the variables being sent through the function

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

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

A

return stops function from running and returns the value to the outside of the function

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

What are arrays used for?

A

store a list of values (strings, numbers, boolean, objects)

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

Describe array literal notation.

A

var = [ ] using brackets

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

How are arrays different from “plain” objects?

A

arrays use an index while objects use keywords to organize data

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

What is the length property of an array?

A

the number of elements in the array

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

How do you calculate the last index of an array?

A

array.length - 1

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

Why do we log things to the console?

A

to follow the the code and for other developers to read

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

What is a method?

A

a function that is a proporty of an object

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

How is a method different from any other function?

A

syntax; with a method you must provide which object its connected to

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

How do you delete an element from an array?

A

splice( start_index , how_many , replace? )

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

How do you append an element to an array?

A

splice( start_index , how_many , replace? )

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

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

A

No, try it out or read some documentation

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

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

A

It does not need to be utilized in every instance

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

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

A

MDN

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

Give 6 examples of comparison operators.

A

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

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

What data type do comparison expressions evaluate to?

A

boolean

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

What is the purpose of a loop?

A

check a condition, more than once

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

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

A

to make the code run or stop the code

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

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

A

one cycle of the code block

53
Q

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

A

before the iteration

54
Q

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

A

at the start of the loop

55
Q

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

A

before every iteration

56
Q

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

A

after each iteration

57
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

58
Q

What does the ++ increment operator do?

A

increase counter by 1

59
Q

How do you iterate through the keys of an object?

A

for..in loop

60
Q

What is the purpose of an if statement?

A

evealuates a condition, if true it will run

61
Q

Is else required in order to use an if statement?

A

no

62
Q

Describe the syntax (structure) of an if statement.

A

if (condition) { }

63
Q

What are the three logical operators?

A

AND&& OR|| !NOT

64
Q

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

A

by comparing their result

65
Q

What are the four components of “the Cascade”.

A
  1. Source Order 2. Inheritance 3. Specificity 4. Important
66
Q

What does the term “source order” mean with respect to CSS?

A

the order that the css rules are writtin on a stylesheet

67
Q

How is it possible for the styles of an element to be applied to its children as well without an additional CSS rule?

A

with inheritance

68
Q

List the three selector types in order of increasing specificity.

A

~

69
Q

Why is using !important considered bad practice?

A

Since it is just a quick fix it is not a long term fix

70
Q

What is the className property of element objects?

A

string containing value of the class attribute

71
Q

How do you update the CSS class attribute of an element using JavaScript?

A

use the className

72
Q

What is the textContent property of element objects?

A

reads any text as a string to add/delete/update

73
Q

How do you update the text within an element using JavaScript?

A

assigning a value to textContent property (var ____ = __nod__.textContent)

74
Q

Is the event parameter of an event listener callback always useful?

A

No, does not need to be utilized

75
Q

Why is storing information about a program in variables better than only storing it in the DOM?

A

so we can store the data and reference it

76
Q

Why do we log things to the console?

A

check data to conform assumptions

77
Q

What is the purpose of events and event handling?

A

to handle something that happned on the we page

78
Q

What do [ ] square brackets mean in function and method syntax documentation?

A

that they are optional

79
Q

What method of element objects lets you set up a function to be called when a specific type of event occurs?

A

________.addEventListener

80
Q

What is a callback function?

A

functions to be used in the future

81
Q

What object is passed into an event listener callback when the event fires?

A

object about info about the event

82
Q

What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?

A

property that references the html element being use in the event

83
Q

What is the difference between these two snippets of code?

element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick())

A

handleClick is a function definition. While handleClick( ) is calling the function and the return value will be the argument

84
Q

What does the new operator do?

A
  1. Creates a blank, plain JavaScript object;
  2. Links (sets the constructor of) the newly created object to another object by setting the other object as its parent prototype;
  3. Passes the newly created object from Step 1 as the this context;
  4. Returns this if the function doesn’t return an object.
85
Q

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

A

prototype property

86
Q

What does the instanceof operator do?

A

if an object is a prototype of a constructor fucntion

87
Q

What kind of inheritance does the JavaScript programming language use?

A

prototype inheritance

88
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

prototypes allow us to base those on others objects

89
Q

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

A

in the Object prototype

90
Q

What is ‘this’ in JavaScript?

A

pointing to Object it is inside

91
Q

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

A

avalible in function code block even though it was never defined or given as a parameter

92
Q

When is the value of ‘this’ determined in a function; call time/definition time?

A

call time

93
Q

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

A

cannot tell until method/function is called

94
Q

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

A

what is to the left of the .

95
Q

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

A

function definition stored as a property of an object

96
Q

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

A

definition has the keyword fucntion anf the { }. call has the ( ) at the end

97
Q

Describe method definition syntax (structure).

A

definition has the keyword function anf the { }

98
Q

Describe method call syntax (structure).

A

call has the ( ) at the end

99
Q

How is a method different from any other function?

A

it is stored within an object as a property

100
Q

What is the defining characteristic of Object-Oriented Programming?

A

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

101
Q

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

A
  1. Abstraction 2. Encapsulation 3. Iheritance 4. Polymorphism
102
Q

What is “abstraction”?

A

turns a complex thing into something easy to use

103
Q

What does API stand for?

A

applications programming interface

104
Q

What is the purpose of an API?

A

give programmers a way to interact with the system in a simplified way

105
Q

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

A

focus

106
Q

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

A

blur

107
Q

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

A

input

108
Q

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

A

submit

109
Q

What does the event.preventDefault() method do?

A

prevent the page from reloading when form is submitted

110
Q

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

A

Reload page

111
Q

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

A

_____.elements.___

112
Q

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

A

.value

113
Q

What is a “callback” function?

A

a function passes into another function as an argument

114
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( )

115
Q

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

A

setInterval( )

116
Q

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

A

0

117
Q

What do setTimeout() and setInterval() return?

A

a unique ID that can be passed through clearInterval( ) to stop

118
Q

What is AJAX?

A

a group of technologies that offer asynchronous functionality

119
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript and XML

120
Q

Which object is built into the browser for making HTTP requests in JavaScript?

A

XMLHttpRequest

121
Q

What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?

A

load event

122
Q

An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?

A

They share the event.target prototype

123
Q

What is a client?

A

initiate request from server

124
Q

What is a server?

A

provides a service (returns a response to client)

125
Q

Which HTTP method does a browser issue to a web server when you visit a URL?

A

GET

126
Q

What three things are on the start-line of an HTTP request message?

A
  1. HTTP Method 2. Request Target (url) 3. HTTP Version (usually 1.1)
127
Q

What three things are on the start-line of an HTTP response message?

A
  1. HTTP Version (1.1) 2. Status Code 3. Status Text (description of code)
128
Q

What are HTTP headers?

A

Specify the request /describe the body included in the message

129
Q

Is a body required for a valid HTTP request or response message?

A

body is optional