JavaScript Flashcards

1
Q

What is the purpose of a loop?

A

repeat code until a condition criteria is met

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

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

A

determine an end state of the loop

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

What does iteration mean in the context of a loop?

A

pass through the loop code

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

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

A

before each iteration

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

When does the initialization expression of a for loop get evaluated

A

beginning, only run once

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

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

A

before every iteration

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

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

A

after the loop code block

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

What does the ++ increment operator do?

A

adds 1 to the variable

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

How do you iterate through the keys of an object?

A

for in loop

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

Why do we log things to the console?

A

To check for bugs, double check our work.

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

What is a “model”?

A

A copy or representation of the original

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

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

A

querySelectorAll()

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

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

A

So the browser does not need to search for it every time it needs it

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

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

A

console.dir()

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

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

A

The browser needs to load all the HTML before JS can be run on it.

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

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

A
an element, id, or class
returns the first element it finds with matching element, id, or class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

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

A

takes element, id, or class

returns all elements with that tag, id, or class

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

Which document is being referred to in the phrase DOM

A

HTML

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

What is the word object referring to in DOM

A

refers to JS objects

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

What is a DOM tree

A

model of the html document represented as a JS object (DOM generally), tree is series of objects elaborating on a chunk of the html document.

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

What is the purpose of events and event handling?

A

add dynamic content, user interactivity, respond to an occurrence

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

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

A

No

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

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

A

addEventListener

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

What is a callback function?

A

function definition passed as a value so it may be invoked later.

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

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

A

the event object with a target object. All possible data pertinent to the event.

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

What is the event.target? If you werent sure, how would you check? Where could you get more information about this?

A

The place where the event occurred. First element most immediate to where the event occurred.

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

What is the difference between these two snippets of code?

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

A

you called one function, the other will be called later by the browser.

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

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

A

focus

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

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

A

blur

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

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

A

input

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

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

A

submit

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

What does the event.preventDefault() method do?

A

prevents an elements default action

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

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

A

elements property

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

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

A

value

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

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

A

Don’t know where your code is broken if it is

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

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

A

You immediately know where your error is

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

What is the event.target

A

The element the event originated from

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

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

A

Bubbling (child to parents)

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

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

A

tagName

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

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

A

css selector and return something the matches the selector (starts nested, queries out)

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

How can you remove an element from the DOM

A

Call remove on the element itself

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

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

A

Every step

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

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

A

Add event listener to every tab

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

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

A

lots of conditionals/conditions

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

What is JSON?

A

data exchange format

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

What are serialization and deserialization?

A

object to string, string to object

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

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

A

JSON.stringify

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

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

A

JSON.parse

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

How do you store data in localStorage?

A

setItem(‘key’, value)

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

How do you retrieve data from localStorage?

A

getItem(‘key’)

53
Q

What data type can localStorage save in the browser?

A

string (JSON)

54
Q

When does the beforeunload event fire on the window object?

A

before the window, current browser path closes (tab closes)

55
Q

What is a method

A

function that is a property of an object

56
Q

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

A

method call has parenthesis

57
Q

Describe method syntax

A

same as function

58
Q

method call syntax

A

same as function

59
Q

What are the four principles of OOP

A

abstraction, inhertance, polymorphism, encapsulation

60
Q

What is astraction?

A

simplifying something complicated (lightswitch)

61
Q

What does API stand for

A

application programming interface

62
Q

purpose of API?

A

tools dev designs to allow others to use the tool they designed in a simpler fashion.

63
Q

What is this in JavaScript?

A

object in which the code is running

64
Q

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

A

available even though it isnt present in the parameter list

65
Q

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

A

call time

66
Q

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

A

you can’t

67
Q

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

A

object to the left of the dot

68
Q

What kind of inheritance does the JavaScript programming language use?

A

prototypal inheritance

69
Q

What is a prototype in JavaScript?

A

to share methods

70
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

prototypal inheritance

71
Q

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

A

proto

72
Q

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

A

prototype property

73
Q

What does the instanceof operator do?

A

returns true or false saying whether right is an instance of object on the left

74
Q

What is a callback function?

A

function passed into another function as an argument (passed as value to be invoked later) (no parenthesis)

75
Q

Besides event listener callback to an element or the document, whats one way to delay the execution of a JS function until some point in the future?

A

setTimeout()

76
Q

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

A

setInterval()

77
Q

What is the default time delay if you omit delay parameter from settimeout or interval?

A

0

78
Q

What do setTimeout and setInterval return?

A

interval ID (integer)

79
Q

What is AJAX?

A

async js and xml

80
Q

What does the AJAX acronym stand for?

A

async js and xml

81
Q

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

A

XMLHttpRequest

82
Q

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

A

addEventListener

83
Q

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

A

both branching off an event prototype

84
Q

What is Node.js

A

a-sync, event driven runtime, JS environment to run JS outside of the browser

85
Q

What can Node.js be used for?

A

back end

86
Q

What is a REPL

A

an environment to code Node.js in terminal

87
Q

When was Node.js created?

A

2009

88
Q

What back end languages have you heard of?

A

Python, Ruby, Java, Rust, Go

89
Q

What is the process object in a Node.js program?

A

It is the object that provides all the information about and control over the current Node.js process

90
Q

How do you access the process object in a Node.js program?

A

process

91
Q

What is the data type of process.argv in Node.js?

A

array

92
Q

Whats a JS module?

A

a single JS file

93
Q

What values passed into a node module local scope?

A

dirname, filename, module, exports, require()

94
Q

truly global variables in a Node.js program?

A

console, setTimeout

95
Q

What is the purpose of module.exports in a Node.js module?

A

Allows you to export bits of code that may be used/accessed by other files

96
Q

How do you import functionality into a Node.js module from another Node.js module?

A

use require()

97
Q

What is the JavaScript Event Loop?

A

Checks callback queue and call stack and moves from queue to stack if call stack is empty

98
Q

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

A

Blocking is synchronous and non-blocking is async, blocking is code holding up the call stack

99
Q

What is a client?

A

Makes a request to a server

100
Q

What is a server?

A

Program or device that sends a response to a client request.

101
Q

What is a host?

A

Hardware a server runs on

102
Q

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

A

GET

103
Q

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

A

Method, Target, Version

104
Q

What are HTTP headers

A

meta data for the request/responses

105
Q

what is on the first line of an HTTP response

A

version, status code, status text

106
Q

Is a body required for a valid HTTP message

A

No

107
Q

What is NPM?

A

website, CLI, and registry

108
Q

What is a package?

A

Code that can be shared/downloaded

109
Q

How can you create a package.json with npm?

A

npm init –yes

110
Q

What is a dependency and how to you add one to a package?

A

npm install (package)

111
Q

What happens when you add a dependency to a package with npm?

A

It updates the code if changes are made

Adds node-modules dir

updates package.json
downloads package from npm registry

112
Q

How do you add express to your package dependencies?

A

npm install express

113
Q

What Express application method starts the server and binds it to a network PORT?

A

listen()

114
Q

How do you mount a middleware with an Express application?

A

app.use, then pass middleware as an argument

115
Q

Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?

A

req and res objects

116
Q

What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?

A

application/json;

117
Q

What is “syntactic sugar”?

A

In computer science, syntactic sugar is syntax within a programming language that is designed to make things easier to read or to express. It makes the language “sweeter” for human use: things can be expressed more clearly, more concisely, or in an alternative style that some may prefer.

118
Q

What is the typeof an ES6 class?

A

object

119
Q

Describe ES6 class syntax.

A
class name {
constructor(constructorNames) {
this.constructorName = constructorNames;
}
method() {
}
}
120
Q

What is “refactoring”?

A

In computer programming and software design, code refactoring is the process of restructuring existing computer code—changing the factoring—without changing its external behavior. Refactoring is intended to improve the design, structure, and/or implementation of the software (its non-functional attributes), while preserving its functionality. Potential advantages of refactoring may include improved code readability and reduced complexity; these can improve the source code’s maintainability and create a simpler, cleaner, or more expressive internal architecture or object model to improve extensibility. Another potential goal for refactoring is improved performance; software engineers face an ongoing challenge to write programs that perform faster or use less memory.

121
Q

What is Webpack?

A

Bundles js modules into a single file

122
Q

How do you add a devDependency to a package?

A

npm install –save-dev

123
Q

What is an NPM script?

A

command line shortcuts you run with npm run …

124
Q

How do you execute Webpack with npm run?

A

npm run build (or any name)

125
Q

What kind of modules can Webpack support?

A

ecmascript file, AMD, commonJS

126
Q

What must the return value of myFunction be if the following expression is possible?
myFunction()();

A

a function

127
Q
What does this code do?
const wrap = value => () => value;
A

returns value?

128
Q

In JavaScript, when is a function’s scope determined; when it is called or when it is defined?

A

when its defined

129
Q

What allows JavaScript functions to “remember” values from their surroundings?

A

the lexical environment created at the time the function was defined (the closure)