Javascript Flashcards

1
Q

Javascript primitives and variables

What is the purpose of variables?

A

Store values

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

Javascript primitives and variables

How do you declare variable?

A

specify the type, leave at least one space, then the name for the variable and end the line with a semicolon ( ; ).

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

Javascript primitives and variables

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

A

const, let, var

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

Javascript primitives and variables

What characters are allowed in variable names?

A

period, underscore, $,#,@

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

Javascript primitives and variables

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

A

Example

let apple
let Apple

they are different

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

Javascript primitives and variables

what is the purpose of a string?

A

It represents text

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

Javascript primitives and variables

What is the purpose of a number?

A

It represents number values

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

Javascript primitives and variables

What is the purpose of a boolean?

A

true/false statements

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

Javascript primitives and variables

What does the = operator mean in Javascript?

A

Compare values and calculation?

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

Javascript primitives and variables

How do you update the value of a variable?

A
var totalPets = 10000;
totalPets  =  23;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Javascript primitives and variables

What is the difference between null and undefined?

A

Null: intentional absence of the value
Undefined: The value doesn’t exist

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

Javascript primitives and variables

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

A

Debugging, or know where you are at

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

Javascript primitives and variables

Give five examples of JavaScript primitives.

A

string, number, undefined, null, boolean

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

Javascript operators and expressions

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

Javascript operators and expressions

What is string concatenation?

A

Adding strings with + operator

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

Javascript operators and expressions

What purpose(s) does the + plus operators serve in Javascript

A

Concatenation

arithmetic

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

Javascript operators and expressions

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 are objects used for?

A

To shape a model, multiple types of data, or functions

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

What are object properties?

A

variables that are attached to the object

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

Describe object literal notation

A

{ key: value}

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 operator

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 or 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

Store the data?

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

What are arrays used for?

A

Store the data?

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

Describe array literal notation

A

var name = [];

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

single variables

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

number of items in an 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

arr.length -1

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

function defined name convertMinutesToseconds with one parameter (minutes) and then opening curlybrace for the code block

expression 60 *minutes being assgined to variable seconds

return of the function value is being assigned to

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

What is a function in JavaScript?

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

Describe the parts of function definition.

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

Describe the parts of a function call?

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

When comparing them side-by-side, what are the difference between a fucntion call and a function

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

What is the difference between a parameter and argument?

A

parameter: placehodler
arguments: giving values

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

Why are function parameters useful?

A

Takes arguments to 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

Check if it’s working

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

What is a method?

A

function that is property of the 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

Connected to any other object

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

Round number down?

A

.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 * array.length

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

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

space, comma,

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

Strings are unchangeable

console log the original string value and console lot the

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

Around 50ish.

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

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

A

No, console.log , they aren’t needed.

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

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

A

A lot aournd 50ish

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

What three-letter acronym should you slways 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
51
Q

Give 6 examples of comparison operators

A

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

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

What data type do comparison expressions evaluate to?

A

Boolean

53
Q

What is the purpose of an if statement?

A

to give conditions to the function

run different code depending on the boolean value

54
Q

Is else required in order to use an if statement?

A

Not necessarily
else is needed if the condition is false
else if is needed to specify a new condition to test, if the first condition is false

55
Q

Describe the syntax ( structure) of an if statement?

A

if (condition) {

56
Q

What are the three logical operators?

A

||
&&
!

57
Q

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

A

Using parenthesis

58
Q

what is the purpose of loop?

A

check condition to run the code block

59
Q

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

A

it keeps the loop going until the certain point

60
Q

what does “iteration? mean in the context of loops?

A

repeating process

61
Q

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

A

before the

62
Q

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

A

as it begins, just 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

before the evaluation of next condition

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

Use a break statement to exit the loop before the condition expression evaluates to false.

66
Q

What does the ++ increment operator do?

A

(adds one to) its operand and returns a value.

67
Q

How do you iterate through the keys of an object?

A

for (var key in object)

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 event?

72
Q

What does the event.preventDefault() method do?

A

resetting, default behavior of that function.

73
Q

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

A

automatically reloads the page

74
Q

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

A

,elements

75
Q

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

A

value property

76
Q

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

A

error is wrong and don’t know hwere

77
Q

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

A

To see step by step, what’s going on.

78
Q

What is JSON?

A

its a form where they keep data

79
Q

What are serialization and deserialization?

A

a process of converting an Object into stream of bytes so that it can be transferred over a network or stored in a persistent storage.

Deserialization:process of decoding the data that is in JSON format into native data type

80
Q

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

A

JSON.stringify
or
manually create the JSON string format

81
Q

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

A

JSON.parse

82
Q

What is a method?

A

function that is a property of an object.

83
Q

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

A

method definition needs to be related with object?

method call is to when we tell javascript to run the code in the function

84
Q

Describe method definition syntax (structure).

A

Function operator.name, parameter, opening curly brace,

85
Q

Describe method call syntax (structure).

A

object.

86
Q

How is a method different from any other function?

A

It needs to be in an object

87
Q

What is the defining characteristic of Object-Oriented Programming?

A

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

88
Q

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

A

Abstraction
Encapsulation
Inheritance
Polymorphism

89
Q

What is “abstraction”?

A

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

DOM

90
Q

What does API stand for?

A

application programming interface

91
Q

What is the purpose of an API?

A

Pass application to each other

92
Q

What is this in JavaScript?

A

Generally an object,

reference electrical scope of when the function is called

93
Q

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

A

It does not need to be explicitly defined.

94
Q

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

A

call time

95
Q

What does this refer to in the following code snippet?

A

character object

96
Q

Given the above character object, what is the result of the following code snippet? Why?

A

It’s-a-me, Mario!

97
Q

Given the above character object, what is the result of the following code snippet? Why?

A

It’s a me, undefined

98
Q

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

A

Can’t be for sure.

99
Q

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

A

look at the scope

100
Q

What kind of inheritance does the JavaScript programming language use?

A

prototype-based inheritance

prototypical

101
Q

What is a prototype in JavaScript?

A

It’s an object with those methods and functions

object that’s inherited down to that prototype

102
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

They exist in prototype

103
Q

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

A

The prototype chain

104
Q

What is a client?

A

computer controlled device

Somebody who makes the request

105
Q

What is a server?

A

a computer program or device that provides a service to another computer programs and its user

handles request

106
Q

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

A

HTTP request GET

107
Q

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

A

method, request URL, http version

108
Q

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

A

protocol version,
status code,
status text

109
Q

What are HTTP headers?

A

headers are way of pssing information between client and server

110
Q

Where would you go if you wanted to learn more about a specific HTTP Header?

A

Check MDN

111
Q

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

A

No, optional

112
Q

What does the new operator do?

A

It creates an object
(There are 4 of them)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new

113
Q

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

A

prototype

114
Q

What does the instanceof operator do?

A

Checks if the prototype property of a constructor appears anywhere in the prototype chain of an object. Returns boolean value.

115
Q

What is a “callback” function?

A

a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.

https://developer.mozilla.org/en-US/docs/Glossary/Callback_function

116
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

global function

setInterval() or setTimeout();

117
Q

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

A

setInterval()

118
Q

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

A

0

119
Q

What do setTimeout() and setInterval() return?

A

return of callback function?

timeoutID or intervalID

120
Q

What is AJAX?

A

Stands for Asynchronous Javascript and XML

programming practice of building webpages using a technology known as XMLHttpRequest.
browser API
working with network to
without having to load a new webpage,

121
Q

What does the AJAX acronymm stand for?

A

Asynchronous Javascript and XML

122
Q

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

A

XMLHttpRequest
var xhr = new XMLHttpRequest();
xhr.open(“GET”, url);

123
Q

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

A

‘load’

124
Q

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

A

it’s the prototype chain.

125
Q

What other events are fired on xrh?

A

progress, load, error, abort,

126
Q

Bonus question

what is xml

A

extensible markup language, no pre-defined tag names

127
Q

What is Array.prototype.filter useful for

higher-order function: array method? or function that calls the function. ask them for clarification

A

When we want to narrow down to specific result

128
Q

What is Array.prototype.map useful for

A

To visit each item in an array to manipulate them

129
Q

What is Array.prototype.reduce useful for?

A

to accumulate a single value from an array