JavaScript Flashcards

1
Q

What is the purpose of variables?

A

Storing values under a specific name and stores data to be called upon when needed

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

How do you declare a variable?

A

Creating the variable with the keywords let const or var and giving it a 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

Using the assignment operator(=) giving the variable a value

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

Letter dollar sign or underscore, can’t start with numbers

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

That variables name like score and Score are different variable names

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

Storing a set of characters.

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

handles numeric data types for mathematical operations

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

Denote true or false, represents is or isn’t. Make decisions.

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

It means a variable is being assigned to a value.

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

You must assign the variable a new value, and not use the keyword since the variable already exists. var is only used for the first time.

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 assigned by the developer purposefully! and means it does not exist. undefined is assigned by the browser and free to use.

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

Labels describe the value or variable being logged, makes it clear what your working when you come back to the code

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

Give five examples of JavaScript primitives.

A

Boolean, int, string, null, undefined

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

Combines two string values together using the add operator, never changes the original makes a new 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

summing numerical data or concantenation

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

Booleans, true or false

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 right operand to the variable and assigns the new value to 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

To group together a set of variables and function

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

What are object properties?

A

A variable that is inside 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

Var name assignment operator(=) { ((object literal)
Properties and values seperates by : and commas separating those
};

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 variablename.nameofproperty

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

Variablename followed by period variable.propertyname or variablename[‘property’]

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 a list of values as a variable that are USUALLY alike, and iterate through them one ate a time if needed

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

Describe array literal notation.

A

var name = [‘string’, false, 3132];

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 object. they have key value pairs like normal objects but the key for each value in an array is its index number. you can also know the number of pieces of data with array.length. also can add additional information with the push method

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

the number of items in the array array.length

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

var lastIndex= arrayname.length - 1

arrayname[lastindex]

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

how does one acesss an array in an object

A

nameofarray. propertyname.arrayname[index position]

cost. rooms1.items[0]

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

how does one access an object in an array

A

costs[2].propertyname

could also be costs[2].products[0.author

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

What is a function in JavaScript?

A

a block of code that is named and accomplishes a task

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

Describe the parts of a function definition.

A

function keyword, optional name (parameter list with optional parameters) {

optional return statement

}

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

Describe the parts of a function call.

A

function name ( arguments optional ) invoked by the parantheses.

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

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

A

function definition is the defining the code and the keyword and calling it is to actually run the code block in the defintion with parentheses and arguments

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

What is the difference between a parameter and an argument?

A

a parameter is placeholder in a function definition, an argument is what a function is called with

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

Why are function parameters useful?

A

parameters gives us muteability (ability to change) the function.

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

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

A

it exits the code block and also produces a value we can use in our program

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

Why do we log things to the console?

A

so that we can check our returned value, debugging tool

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

What is a method?

A

a method is a function that is a property of an object

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

How is a method different from any other function?

A

methods are associated with objects, functions are not

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

How do you remove the last element from an array?

A

.pop() removes the last element and returns it

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

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

A

math.floor() returns nearest integer that is less than or equal to given number

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

How do you delete an element from an array?

A

splice(index position, number of items)

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

How do you append an element to an array?

A

push() adds the elements to the end of an array

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

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

A

No they do not, console.log(stringname) strings are immutable

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

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

A

a lot

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

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

A

no example pop method

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

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

A

a lot

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

Give 6 examples of comparison operators.

A

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

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

What data type do comparison expressions evaluate to?

A

booleans. true and false

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

What is the purpose of an if statement?

A

to check a condition true or false whether to run a certain code block

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

Is else required in order to use an if statement?

A

no it is not

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

Describe the syntax (structure) of an if statement

A
if keyword ( condition ) {
code block
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
58
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
59
Q

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

A

logical operators || &&

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

What is the purpose of a loop?

A

offer. a quick way to do something repeatedly, repeat functionality

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

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

A

a conditional expression in a loop signifies a decision to either execute the code block if condition is met or stop

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

for loop parts

A

inital expression, conditional statement,

code block

final expression

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

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

A

each time the code inside the block is run

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

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

A

before it executes the code block

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

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

A

before anything, one time

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

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

A

after the initialization, before the code block, and after the final expression

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

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

A

after the code block executes and before the condition runs again

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

Besides a return statement, which exits its entire function block, which keyword

A

break;

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

What does the ++ increment operator do?

A

incremenes by 1 and adds it to the variable and reassigns to the variable

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

How do you iterate through the keys of an object?

A

for in loop

71
Q

Why do we log things to the console?

A

to debug, and check values

72
Q

What is a “model”?

A

a framework or representation of something

73
Q

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

A

the html document

74
Q

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

A

javascript object that is modeling the html documents content

75
Q

What is a DOM Tree?

A

all the info necessary to describe an element and its content

div which branches to children, and there child content

76
Q

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

A

querySelector() and getElementById

77
Q

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

A

querySelectorAll() getElementsByClassName

78
Q

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

A

so that you can save that reference to the object in the dom tree for multiple uses

reference to the object in the dom tree is an element

79
Q

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

A

console.dir

80
Q

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

A

it needs to parse all the data before javascript code can access them

81
Q

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

A

it takes a string of css selector, and returns the first matching element

82
Q

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

A

takes a string of css selector and returns all matching elements

83
Q

Why do we log things to the console?

A

to check the value and debug

84
Q

What is the purpose of events and event handling?

A

Events are signals fired inside the browser window that notify of changes in the browser or operating system environment. event handling allows things to happen in response to that event occurring, interactivity

85
Q

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

A

no parameters are optional

86
Q

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

A

addEventListener

87
Q

What is a callback function?

A

a function passed as an arguement to another function

88
Q

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

A

the event object which holds alll the detailed information about the event

89
Q

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

A

reference onto the target in which the event was dispatched. console.log it.

90
Q

What is the difference between these two snippets of code?

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

A

first one happens when an event occurs, other happens when the page loads

91
Q

What is the className property of element objects?

A
contains the current className proprety of the element. The className property of the Element interface gets and sets the value of the class attribute of the specified element
you can set a different value
92
Q

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

A

.className property

93
Q

What is the textContent property of element objects?

A

all text hidden or not of the dom element

94
Q

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

A

query.text content = new value.

95
Q

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

A

no not always

96
Q

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

A

more complicated

97
Q

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

A

they are in the same language you are working with.

98
Q

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

A

focus event

99
Q

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

A

blur

100
Q

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

A

input

101
Q

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

A

submit triggers event, the event is fired on the form.

always present and at the top for submit event listeners
prevent default

102
Q

What does the event.preventDefault() method do?

A

prevents default action from happening

always present and at the top for submit event listeners

103
Q

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

A

reloads the page

104
Q

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

A

elements

105
Q

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

A

value

106
Q

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

A

u don’t know which line of code in that block is wrong or if there are multiple issues

107
Q

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

A

you get to see errors quickly, keep track in real time

108
Q

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

A

No it just creates the element node is not yet apart of the dom tree.

109
Q

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

A

parentelement.appendchild(childelement)

110
Q

What do you pass as the arguments to the element.setAttribute() method?

A

the arguements are the attribute name and value

111
Q

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

A

create element , configure, you must append the child elements to its parent element. create a reference to where to attach it too, query selector.

112
Q

What is the textContent property of an element object for?

A

so you can change or get all the text properties of an object

113
Q

Name two ways to set the class attribute of a DOM element.

A

setAttribute, element.className

114
Q

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

A

multi-use, future use.

115
Q

Give two examples of media features that you can query in an @media rule.

A

min width max-width

116
Q

Which HTML meta tag is used in mobile-responsive web pages?

A

html viewport

117
Q

What is the event.target?

A

its where the event is originated from

118
Q

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

A

through the concept of bubbling, event starts at a specific node at flows outward to the least specific nodes

119
Q

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

A

tagName

120
Q

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

A

event.target.closest(selector) closest selector ancestor element opposite of query selector
this method traverses the element and finds a node that matches the css selector that is passed as an arguement.

the return is the closest ancestor element.

121
Q

How can you remove an element from the DOM?

A

element.remove();

122
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

add that event listener to the parent element to see if the target.event && event.target.tagName == ‘ELEMENT’

123
Q

What is the event.target?

A

event.target is where the event is fired at.

124
Q

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

A

removes the element from the document flow

125
Q

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

A

the css selector as a string, it returns the appropriate boolean if it matches the selector

126
Q

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

A

getAttribute method arguement = string of the name of the attribute

127
Q

At what steps of the solution would it be helpful to log things to the console?

A

to check the value of different variables, any step

128
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

u would have to make an event listner specifically for that tab?

129
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

huge conditional block

130
Q

What is JSON?

A

short for javascript object notation. text based format following object syntax that is a string.

131
Q

What are serialization and deserialization?

A

serialization is the data turned into a serialized string of bytes, all in the same location. deserialization is taking those localized string of bytes and bringing back the complexities.

dog -> object {name:elly , age: 16} -> 01010101010 ——- 01010101010 -> object {name:elly , age: 16} -> dog

132
Q

Why are serialization and deserialization useful?

A

you can store objects into memory which is then stored in disks or sent over a network.

133
Q

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

A

json.stringify(object)

134
Q

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

A

json.parse(jsonobject)

135
Q

How do you store data in localStorage?

A

localstorage.setItem(property name, property value)

136
Q

How do you retrieve data from localStorage?

A

getItem(‘property name’)

137
Q

What data type can localStorage save in the browser?

A

strings

138
Q

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

A

when u close a tab/refresh tab close/crash browser, everything about to close

139
Q

What is a method?

A

a method is a function that is a property of an object

140
Q

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

A

a method definition will have the code block and parameters property name : function keyword

141
Q

Describe method definition syntax (structure).

A
var obj = {
property name: function () {
code block
}
142
Q

Describe method call syntax (structure).

A

objectname.methodName(arguements)

143
Q

How is a method different from any other function?

A

it is associated with an object.

144
Q

What is the defining characteristic of Object-Oriented Programming?

A

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

145
Q

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

A

Abstraction
Encapsulation
Inheritance
Polymorphism

146
Q

What is “abstraction”?

A

The most important part of the term “abstraction” boils down to being able to work with (possibly) complex things in simple ways

147
Q

What does API stand for?

A

Application Programming Interfaces (APIs) are constructs made available in programming languages to allow developers to create complex functionality more easily. They abstract more complex code away from you, providing some easier syntax to use in its place.

148
Q

What is the purpose of an API?

A

They abstract more complex code away from you, providing some easier syntax to use in its place.

149
Q

What is this in JavaScript

A

implicit parameter allows us to view the object from when it is being invoked.

the value of this is determined when the function is called, not when it is defined.

150
Q

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

A

it exists without having to be declared on included in the paramter list.

151
Q

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

A

call time

152
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, has not been called yet.

153
Q

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

A

its a me mario because greet is being invoked

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

its a me, undefined!

no dot to the left , object = window. firstname property on window does not exist.

155
Q

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

A

can’t guarantee the value of this will be in a definition

156
Q

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

A

whatever is left of the dot, if no dot global scope, window object.

157
Q

What kind of inheritance does the JavaScript programming language use?

A

prototypal inheritance. Javascript objects give certain behavors (methods) or data(properties) to other objects.

158
Q

What is a prototype in JavaScript?

A

prototypes are the mechanism by which JavaScript objects inherit features from one another.

159
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

by assigning them a prototype that has those methods

160
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. nearest prototypal chain down the line.

161
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.

creates a new object.
value of prototype property and make that property a new property on the object called __proto__.
executes function with arguements.
it returns the object.

Creating an object with a user-defined constructor function requires two steps

  1. Define the object type by writing a function that specifies its name and properties. For example, a constructor function to create an object Foo might look like this:
  2. Create an instance of the object with new
162
Q

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

A

prototype.

163
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.

This usually means object was constructed with constructor.

164
Q

What is a “callback” function?

A

a function that you call at some point in the future.

165
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

or setInterval

166
Q

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

A

set Interval

167
Q

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

A

0, gets put into the queue immediately, will happen immediately if there is nothing else to do

168
Q

What do setTimeout() and setInterval() return?

A

set timeout returns a timeoutID which is a positive integer value which identifies the timer created by the call to setTimeout().

setInterval returns a intervalID which is a numeric, non-zero value which identifies the timer created by the call to setInterval(); this value can be passed to clearInterval() to cancel the interval.

169
Q

difference between settimeout and setinterval

A

setTimeout() is one time, setInterval is multiple times

170
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript and XML

171
Q

What is AJAX?

A

group of technologies that offer asynchronous functionality to the browser.

172
Q

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

A

XMLHttpRequest object

173
Q

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

A

load

174
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

prototypal inheritance