Javascript Flashcards

1
Q

What is the purpose of a number?

A

To assign numerical value

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

What is the purpose of a boolean?

A

To determine if something is true or false

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

What does the = operator mean in JavaScript?

A

It says that you are going to assign a value to a variable

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

How do you update the value of a variable?

A

By recalling the variable by the name and using the assignment operator to assign it a new value

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

What is the difference between null and undefined?

A

null is an assigned value. It means nothing.(intentional empty) undefined means a variable has been declared but not defined yet

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

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

A

to help you debug, but if you do not include “labels”, it can be very confusing instead of helpful

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

What is string concatenation?

A

Taking two strains and putting them together

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

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

A

To add values and concatenate

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

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

A

adds the value on the right, to the variable on the left, and then assigns that value back into the variable on the left

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

What are arrays used for?

A

To store a list of values

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

Describe array literal notation.

A

The values are assigned to the array inside a pair of square brackets, and each value is separated by a comma.

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

How are arrays different from “plain” objects?

A

It holds a list of related values in order, white object holds list of values out of order

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

What is the length property of an array?

A

It holds the number of items in the array

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

How do you calculate the last index of an array?

A

Subtracting 1 from the length of an array

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

What are objects used for?

A

To group together a set of variables and functions to create a model

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

Object is contained by curly braces,

You separate each key from its value by using a colon, separate each property and method with a comma.

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

Use keyword delete operator followed by dot notation

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

Using dot notation or brackets notation

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

What is a function in JavaScript?

A

Functions allow you to package up code for use later in your program.

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

Describe the parts of a function definition:

A

Function keyword to bring a new function
An optional name
A comma-separated list of zero or more parameters
The start of the code block enclosed by curly braces
An optional return statement

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

Describe the parts of a function call.

A

The function’s name and a comma-separated list of zero or more arguments surrounded by ()

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

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

A

Call, recalls the function and executes the code to run, definition defines and states what the code is going to do

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

What is the difference between a parameter and an argument?

A

Parameters are used to define a function, arguments are used to call a function.

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

Why are function parameters useful?

A

Because they allow to function to be more flexible

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

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

A

Causes the function to produce a value we use in our program

Prevents any more code in the code block from being run

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

Why do we log things to the console?

A

To use as a debugging tool and learning to play and learn about JS

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

What is a method?

A

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

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

How is a method different from any other function?

A

A method is associated with an object while a function is not

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

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

A

floor()

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

How do you append an element to an array?

A

push() unshift()

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

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

A

No they don’t change original string, assigning original string to a var and checking with new string

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

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

A

60+ methods

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

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

A

no

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

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

A

30+ methods

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

Give 6 examples of comparison operators.

A

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

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

What is the purpose of an if statement?

A

guides a program to make decisions based on specified criteria

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

Describe the syntax (structure) of an if statement.

A

If ( exp ) {
Code block to run
}

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

What are the three logical operators?

A

And or not

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

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

A

With and / or logical operators

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

What is the purpose of a loop?

A

To perform repeated tasks based on a condition

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

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

A

Tells the loop when to stop

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

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

A

Repetition of a function or process

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

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

A

before executing the statement. And one after

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

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

A

Before each loop iteration, just once

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

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

A

Each time before the loop runs

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

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

A

At the end of each loop iteration.

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

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

What does the ++ increment operator do?

A

Increase the number by 1 and reassigns the value back into variable

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

How do you iterate through the keys of an object?

A

Using a for in loop

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

Why do we log things to the console?

A

To debug and make sure things are working.

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

What is a “model”?

A

The representation of something

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

Which “document” is being referred to in the phrase Document Object Model?

A

The document which is being represented on the web page

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

What is the word “object” referring to in the phrase Document Object Model?

A

Its referring to each different part of the page being loaded in the window

66
Q

What is a DOM Tree?

A

It is the model of a web page

67
Q

Give two examples of document methods that retrieve a single element from the DOM.

A

getElementByID & querySelector

68
Q

Give one example of a document method that retrieves multiple elements from the DOM at once.

A

getElementsbyClassName

69
Q

Why might you want to assign the return value of a DOM query to a variable?

A

It helps page speed, by saving the reference location of the value in the Dom tree.

70
Q

What console method allows you to inspect the properties of a DOM element object?

A

console.dir

71
Q

Why would a tag need to be placed at the bottom of the HTML content instead of at the top?

A

To help the page load faster by loading the html elements first.

72
Q

What does document.querySelector() take as its argument and what does it return?

A

Css selector syntax and returns only the first of the matching elements

73
Q

What does document.querySelectorAll() take as its argument and what does it return?

A

Css selector syntax and returns all of those that match

74
Q

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

A

Focus event

75
Q

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

A

Blur event

76
Q

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

A

Form event

77
Q

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

A

Submit event

78
Q

What does the event.preventDefault() method do?

A

Cancel default behavior of event

79
Q

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

A

Reload the page with its return values in the address bar

80
Q

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

A

Value attribute

81
Q

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

A

Bugs and issues / broken code

82
Q

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

A

You are able to check if any code is broken or if anything is not showing correct output

83
Q

Are all possible parameters required to use a JavaScript method or function?

A

no

84
Q

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

A

AddEventListerner Function

85
Q

What is a callback function?

A

Is any function that is passed to another function but is not called.

86
Q

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

A

Event object

87
Q

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

A

Is the element which dispatches the element. MDN

88
Q

What is the className property of element objects?

A

Gets and sets the value of the class attribute of the specified element

89
Q

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

A

element.className = “class”;

90
Q

What is the textContent property of element objects?

A

Property that stores the text content of the element

91
Q

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

A

.textcontent =

92
Q

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

A

No

93
Q

Would this assignment be simpler or more complicated if we didn’t use a variable to keep track of the number of clicks?

A

More complicated, we would have to access the Dom as the source of truth.

94
Q

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

A

Because we can refer back it later and reuse as many times as we need.

95
Q

Does thedocument.createElement()method insert a new element into the page?

A

no

96
Q
  • How do you add an element as a child to another element?

A


appendChild()

97
Q
  • What do you pass as the arguments to theelement.setAttribute()method?
A


name to attribute, value

98
Q

What steps do you need to take in order to insert a new element into the page?

A

appendChild that new element to its parent

99
Q
  • What is thetextContentproperty of an element object for?

A

the text content and all its decendaces

100
Q
  • Name two ways to set theclassattribute of a DOM element.
.
A

className, setAttribute()

101
Q

What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?

A

that it is repeatable to work with data structures, the availability to separate function so it doesn’t affect anything else in the program , incase we need to change data at a later point

102
Q

What is the event.target?

A

The target event propertyreturns the element that triggered the event

103
Q

Why is it possible to listen for events on one element that actually happen its descendent elements?

A

Because of event flow

104
Q

What DOM element property tells you what type of element it is

A

nodeName / Tagname

105
Q

What does the element.closest() method take as its argument and what does it return?
How can you remove an element from the DOM?

A

returnsthe first ancestor of the selected element
Takes a selector as the argument
With element.remove() function

106
Q

If you wanted to insert new clickable DOM elements into the page using JavaScript, how could you avoid adding an event listener to every new element individually?

A

By adding an event listener to its parent element

107
Q

What is the event.target?

A

Target of the event being interacted with

108
Q

What is the affect of setting an element to display: none?

A

It hides all the content within that element

109
Q

What does the element.matches() method take as an argument and what does it return?

A

A selector as its argument and returns true or false value

110
Q

How can you retrieve the value of an element’s attribute?

A

getAttribute() method

111
Q

If you were to add another tab and view to your HTML, but you didn’t use event delegation, how would your JavaScript code be written instead?

A

add individual addeventlisteners for each elemnt

112
Q

If you didn’t use a loop to conditionally show or hide the views in the page, how would your JavaScript code be written instead?

A

Using an if statement if one tab is ‘showing’ hide all other tabs

113
Q

What is JSON?

A

JSON is a lightweight format for storing and transporting data.

114
Q

What are serialization and deserialization?

A

Serialization is a mechanism of converting the state of an object into a byte stream
Deserialization is the reverse process where the byte stream is used to recreate the actual Java object in memory.

115
Q

Why are serialization and deserialization useful?

A

They help to sa¥ve file¥¥s onto the local disk or sent over the network to any other machine

116
Q

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

A

stringify()

117
Q

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

A

JSON.parse( string, function )

118
Q

How do you store data in localStorage?

A

localStorage.setItem() KEY, VALUE

119
Q

How do you retrieve data from localStorage?

A

localStorage.getItem()

120
Q

What data type can localStorage save in the browser?

A

JSON Data

121
Q

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

A

is fired when the window, the document and its resources are about to be unloaded.

122
Q

What is a method?

A

Is a function which is a property of an object

123
Q

Describe method definition syntax (structure).

A

Object {method: function() {} }

124
Q

Describe method call syntax (structure).

A

Object.method()

125
Q

How is a method different from any other function?

A

Difference is that a method is associated with an object while a function is not

126
Q

What is the defining characteristic of Object-Oriented Programming?

A

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

127
Q

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

A

Abstraction, encapsulation, inheritance, polymorphism

128
Q

What is “abstraction”?

A

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

129
Q

What does API stand for?

A

Application programming interface

130
Q

What is the purpose of an API?

A

its purpose is to facilitate a way for two or more computer programs to communicate with each other.

131
Q

What is this in JavaScript?

A

the this keyword refers to an object. Which object depends on how this is being invoked (used or called).

132
Q

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

A

meaning that it is available in a function’s code block even though it was never included in the function’s parameter list or declared withvar

133
Q

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

A

Call time

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

Object character

135
Q

Given the abovecharacterobject, what is the result of the following code snippet? Why?

A

It returns the greet function inside character object, because this is being referred to character object

136
Q

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

A

It returns It’s-a-me, undefined!, because the function if not being called.

137
Q

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

A

By seeing what object the this method is inside of

138
Q

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

A

By looking at what is left of the period

139
Q

What kind of inheritance does the JavaScript programming language use?

A

Prototype based inheritance

140
Q

What is a prototype in JavaScript?

A

The prototype is an object that is associated with every functions and objects by default in JavaScript

141
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

Because of prototypes property’s they inherit.

142
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 its prototype chain

143
Q

What does the new operator do?

A

The new operator 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

144
Q

What does the instanceof operator do?

A

is used to check the type of an object at the run time. It returns a boolean value(true or false).

145
Q

What is a “callback” function?

A

Acallback functionis a function passed into another function as an argument,

146
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

By using the setTimeout function

147
Q

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

A

Using the setinterval function

148
Q

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

A

0

149
Q

What do setTimeout() and setInterval() return?

A

A unique intervalID

150
Q

What is a client?

A

a client is any computer hardware or software device that requests access to a service provided by a server

151
Q

What is a server?

A

A server isa computer program or device that provides a service to another computer program and its user, also known as the client.

152
Q

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

A

GET

153
Q

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

A

An HTTP method, a verb (like GET , PUT or POST )
The request target, usually a URL,
HTTP version

154
Q

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

A

The protocol version, usually HTTP/1.1 .
A status code, indicating success or failure of the request. Common status codes are 200 , 404 , or 302.
A status text.

155
Q

What are HTTP headers?

A

HTTP headers let the client and the server pass additional information with an HTTP request or response.

156
Q

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

A

no, requests fetching resources, likeGET,HEAD,DELETE, orOPTIONS, usually don’t need one.

157
Q

What is AJAX?

A

Is a technique for loading data into part of a page without having to refresh the entire page.

158
Q

What does the AJAX acronym stand for?

A

Asynchronous Javascript and XML

159
Q

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

A

XMLHttpRequest

160
Q

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

A

Load event

161
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

They both share a prototype object, prototype inheritance