JavaScript Flashcards

1
Q

What is the purpose of variables?

A

Stores 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

Variable keyword + variable names = variable value;

Must give variable 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

Assign the value using an assignment operator

= sign

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

$ or underscore

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

camelCase - first word lowercase, any additional words have first letter capitalized

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

Working with any kind of text to add new content to a page

Can contain HTML markup

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

Involves counting or calculating sums

Numeric values

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

Give values of true or false

Helps determine which part of the script should run

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 operator

Assigns names to 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

Change the 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: intentional absence of the value. Undefined: It means the value does not exist in the compiler.

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

Name of what is for

helps self and others to define what it is used for

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

Give five examples of JavaScript primitives.

A

undefined, null, boolean, string, and number

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

Numeric

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

What is string concatenation?

A

Process of joining two or more strings to create one 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

Addition as well as 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

Comparison operators

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

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

What are arrays used for?

A

Storing values as a list

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

Describe array literal notation.

A

Values assigned to the array inside of a pair of square brackets, each value separated by a comma.
Don’t need to be same data type

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

How are arrays different from “plain” objects?

A

Can combine arrays and objects to create a data structure

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

What is the length property of an array?

A

sets or returns the number of elements in an array

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

How do you calculate the last index of an array?

A

Name.length - 1

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

Why do we log things to the console?

A

Making sure everything is working and running correctly

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

What is a method?

A

Function which is a property of an object

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

How is a method different from any other function?

A

method is associated with an object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
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
29
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
30
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
31
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
32
Q

How do you append an element to an array?

A

unshift()

push()

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

How do you break a string up into an array?

A

Call the split() method

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

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

A

No, immutable - log it to the console

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

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

A

50+

Allow work with strings after been created

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

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

A

3

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

Give 6 examples of comparison operators.

A

< - less than, > - greater than, != - not equal to, || - logical or, === - strictly equal to, && - logical and

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

What is the purpose of an if statement?

A

Evaluates (checks) a condition

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

Describe the syntax (structure) of an if statement.

A

Keyword, condition, opening curly brace, code to execute if value true, closing curly brace

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

What are the three logical operators?

A

&& - logical and, || logical or, ! logical not

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

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

A

Using a logical and && - logical or ||

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

What is the purpose of a loop?

A

Check a condition that will run the code block

Repeat a block of code

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

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

A

Is evaluated n gets tested every time the loop runs

It determines if and when the loop stops.

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

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

A

Means how many times the loop will loop.

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

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

A

evaluated before each pass through the loop

Before each iteration to decide whether we should stop or not

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

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

A

evaluated once before the loop begins

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

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

A

evaluated before each loop iteration

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

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

A

evaluated at the end of each loop iteration

After the code block runs

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

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

What does the ++ increment operator do?

A

Adds one to the operand.

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

How do you iterate through the keys of an object?

A

Using the for in loop.

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

Why do we log things to the console?

A

Checks to see if the code is running and working properly

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

What is a “model”?

A

Representation of something

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

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

A

The elements of the page

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

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

A

Each node is an object with methods and properties

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

What is a DOM Tree?

A

Model of the webpage

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

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

A

getElementById( )

querySelector( )

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

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

A

document.querySelectorAll()

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

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

A

document.querySelectorAll()

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

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

A

To avoid having the browser look for that location again.

65
Q

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

A

console.dir()

66
Q

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

A

browser needs to go through all the HTML elements before the JavaScript code can access it

67
Q

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

A

A css selector and it returns the first element in doc matching the specified set of CSS selectors
Or null if no matches

68
Q

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

A

A css selector and it returns a Node List with all the properties of that selector.

69
Q

What is the className property of element objects?

A

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

70
Q

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

A

Query for element, get new value and assign using the className property.

71
Q

What is the textContent property of element objects?

A

Property that gets and sets the text content of an element

Holds parents and children elements - all text inside the element

72
Q

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

A

Query selector + new value onto textContent property

73
Q

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

A

not always

74
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

75
Q

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

A

storing DOM locations in a variable prevents the browser from looking for the information.

76
Q

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

A

focus

77
Q

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

A

blur

78
Q

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

A

input

79
Q

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

A

submit

80
Q

What does the event.preventDefault() method do?

A

tells the user that if the event does not get explicitly handled, its default action should not be taken as it normally would be

81
Q

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

A

Reloads the page

82
Q

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

A

elements

83
Q

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

A

value

84
Q

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

A

unchecked bugs, may not be running properly

85
Q

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

A

able to see where issues occur; debugging

86
Q

What is a method?

A

A piece of code that is called by a name that is associated with an object

87
Q

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

A
Method call has ( ).
calculator.getAverage([23,423,4234])
getAvg method of the calculator obj
Method definition
Has the function keyword and function code block
Getting assigned to a property
88
Q

Describe method definition syntax (structure).

A
  1. Method name;
  2. Function keyword;
  3. Parameters (optional);
  4. Opening curly brace;
  5. Code;
  6. Closing curly brace
89
Q

Describe method call syntax (structure).

A
  1. Object;
  2. Method name;
  3. Arguments inside parentheses (optional)
90
Q

How is a method different from any other function?

A

function stored inside an object as a property

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
Document Object Model is a software example of an abstraction. It is not the original HTML text, but instead a tree of JavaScript objects with convenient methods and properties that allow you to manipulate the document as the user interacts with it.

94
Q

What does API stand for?

A

application programming interface

95
Q

What is the purpose of an API?

A

The connection between computers or computer programs

Converting information from one application to another.

96
Q

What is this in JavaScript?

A

Refers to an object

can be recognized as “the object to the left of the dot” when the function is called (as a method).

97
Q

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

A

available in a function’s code block even though it was never included in the function’s parameter list or declared with var
Dont have to state it

98
Q

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

A

the value of this is determined when the function is called, not when it is defined
when you call a function, it’s this will be given the value of the global window object.

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 - method is not being called

100
Q

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

A

The message including Mario’s name in message bc character name was called to the firstName with this

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

undefined, nothing before hello - window

this = window

102
Q

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

A

The value of “this” will be the object that is calling it

103
Q

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

A

The value of this will be in relation to who made the call

104
Q

What kind of inheritance does the JavaScript programming language use?

A

Prototype-based inheritance

105
Q

What is a prototype in JavaScript?

A

JavaScript prototype is an object that contains properties and 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

Because those methods are inside a prototype 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

in the prototype object

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

110
Q

What does the instanceof operator do?

A

It checks if a prototype property appears anywhere in the prototype chain of an object
Return value is boolean

111
Q

What is a “callback” function?

A

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

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

Using setTimeout( ) function

113
Q

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

A

Using setInterval() function

114
Q

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

A

0

115
Q

What do setTimeout() and setInterval() return?

A

They return a timeoutID or intervalID, which are positive integer values.

116
Q

What is AJAX?

A

Allows you to request data from a server and load it without having to refresh the entire page

117
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript And XML.

118
Q

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

A

XMLRequest object

119
Q

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

A

Load event

120
Q

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

A

Because both descend from the same class being EventTarget.

121
Q

What is JSON?

A

Javascript object notation
common data interchange format used to send and store information in computer systems
Text-based data format following JavaScript object syntax, exists as a string

122
Q

What are serialization and deserialization?

A

Serialization is the process of turning an object in memory into a stream of bytes
can do stuff like store it on disk or send it over the network.
Deserialization is the reverse process
turning a stream of bytes into an object in memory

123
Q

Why are serialization and deserialization useful?

A

Transmit data across network

124
Q

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

A

Using JSON.Stringify( ).

125
Q

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

A

Using JSON.parse()

126
Q

What is a code block? What are some examples of a code block?

A

​​code blocks are denoted by curly braces { }

ex: if, for, while

127
Q

What does block scope mean?

A

the variable inside the block is a new variable and it shadows the variable declared at the top of the script

128
Q

What is the scope of a variable declared with const or let?

A

Blocked scope variables

129
Q

What is the difference between let and const?

A

const - denotes that a variable is a constant and can’t be reassigned

let - can be reassigned

130
Q

Why is it possible to .push() a new value into a const variable that points to an Array?

A

the actual value to which the const variable reference is not immutable

131
Q

How should you decide on which type of declaration to use?

A

if the variable will be reassigned

use let otherwise use const

132
Q

What is the syntax for writing a template literal?

A

wrapping your text in backticks and writing expressions inside ${ }

133
Q

What is “string interpolation”?

A

replacing placeholders with values in a string literal

134
Q

What is destructuring, conceptually?

A

extracting data from arrays or objects into smaller parts

135
Q

What is the syntax for Object destructuring?

A

let / const keyword { propertyOfObj: nameOfVariable} = object

136
Q

What is the syntax for Array destructuring?

A

let / const keyword [varName1, varName2, etc] = array;

137
Q

How can you tell the difference between destructuring and creating Object/Array literals?

A

creating - the name of the variable comes first

destructuring - curly brace / square bracket comes first

138
Q

What is the syntax for defining an arrow function?

A

(parameter) => {code block}

139
Q

When an arrow function’s body is left without curly braces, what changes in its functionality?

A

without curly braces, it can only be a single expression, with curly braces, it needs a return keyword

140
Q

How is the value of this determined within an arrow function?

A

an arrow function doesn’t have it’s own this value and captures the this value of the lexical scope (the outer function)

141
Q

What is the JavaScript Event Loop?

A

runtime model based on an event loop, which is responsible for executing the code, collecting and processing events, and executing queued sub-task

142
Q

What is the difference between “blocking” and “non-blocking” with respect to how code is executed?

A

A blocking assignment takes effect immediately when it is processed.
Stuff that’s blocking is on the stack , nothing else can happen until it pops off the stack
A nonblocking assignment takes place at the end of processing the current “time delta” - can move on to another task, asynchronous

143
Q

What is a client?

A

piece of computer hardware or software that accesses a service made available by a server as part of the client–server model of computer networks.
Server requesters

144
Q

What is a server?

A

Service provider

provides functionality for other programs or devices - clients

145
Q

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

A

GET request

146
Q

What is on the first line of an HTTP request message?

A

HTTP method, request target and HTTP version

147
Q

What is on the first line of an HTTP response message?

A

The protocol version, status code and status text.

148
Q

What are HTTP headers?

A

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

149
Q

Is a body required for a valid HTTP message?

A

no

150
Q

What are the three states a Promise can be in?

A

pending

fulfilled OR rejected

151
Q

How do you handle the fulfillment of a Promise?

A

promise.then( )

152
Q

How do you handle the rejection of a Promise?

A

then() and a final catch() statement

153
Q

What is Array.prototype.filter useful for?

A

It’s useful for getting just the values you need out of an array and ignoring the rest.

154
Q

What is Array.prototype.map useful for?

A

Creating a new array containing the transformed elements of another.

useful for calling a function on every element of an array and assigning the results to a new array, without modifying the original.

155
Q

What is Array.prototype.reduce useful for?

A

It’s useful for calling a function on every element of an array and storing the combined result in a single output value

Combining elements of an array into a single value

156
Q

What is “syntactic sugar”?

A

Designed to make things/language easier to read or to express

157
Q

What is the typeof an ES6 class?

A

function

158
Q

What is “refactoring”?

A

the process of changing a software system in such a way that it does not alter the function of the code yet improves its internal structure.

159
Q

Describe ES6 class syntax.

A
Class declaration keyword, curly brace for the class body
Prototype methods
Closing curly brace for class body