Javascript Flashcards

1
Q

What is the purpose of variables?

A

To store data to use again in the future.

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

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

A

var keyword var name = var value;

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

What characters are allowed in variable names?

A

Letters, Numbers, Underscore, and dollarsign.

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

What does the = operator mean in JavaScript?

A

Assignment.

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

Uppercase and lowercase variable names are not equal,

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

sequence of characters that represent text

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

represents a numeric data type that allows us to perform mathematical operations on it

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

Lets the computers ultimately decide what to do or not do.

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

What is the difference between null and undefined?

A

undefined: JavaScript’s method of saying “empty”
null: developer’s way of saying “empty”; assigned intentionally

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

What is string concatenation?

A

adding two strings together

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

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

A

addition and string concatenation

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

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

A

adds/concatenates the value on the right with the value on the left and then assigns it to the variable on the left.

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

What are objects used for?

A

to group relevant data together

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

What are object properties?

A

variables that live within an object

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

Describe object literal notation.

A

var keyword var name = { };

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

How do you remove a property from an object?

A

Using the delete operator

delete object.property

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

What are the two ways to get or update the value of a property?

A

dot notation (object.property = value)

bracket notation (object[‘property’] = value)

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

What are arrays used for?

A

Useful when working with lists or groups of similar data

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

Describe array literal notation.

A

var varName = [list contents (separated by comma)]

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

How are arrays different from “plain” objects?

A

values assigned to index numbers rather than keys

order is preserved in arrays

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

What is the length property of an array?

A

returns how many things are stored in the list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
How do you calculate the last index of an array?
array.length - 1
26
Give five examples of JavaScript primitives.
Number, Boolean, String, Null, Undefined
27
Why is it a good habit to include "labels" when you log values to the browser console?
To know which variable you are logging.
28
How do you update the value of a variable?
var name = new value;
29
How do you declare a variable?
Var keyword var name;
30
What is a function in JavaScript?
A block of code that has a specific purpose and can be reused as many times as needed
31
Describe the parts of a function definition.
``` function functionName (optional Parameter) { optional Return; } ```
32
Describe the parts of a function call.
functionName( );
33
What is the difference between a parameter and an argument?
Functions are defined with parameters and called with arguments.
34
What two effects does a return statement have on the behavior of a function?
Causes the function to produce a value and also exits the function.
35
Why are function parameters useful?
Can achieve different results depending on the data passed in
36
When comparing them side-by-side, what are the differences between a function call and a function definition?
Function definition has parameters and a code block and function call has arguments.
37
Why do we log things to the console?
To check if the value received is as expected.
38
What is a method?
A function that is a property of an object.
39
How is a method different from any other function?
They are accessed using dot notation.
40
How do you round a number down to the nearest integer?
Math.floor( )
41
How do you generate a random number?
Math.Random( )
42
How do you delete an element from an array?
Array.splice( )
43
How do you append an element to an array?
Array.push( )
44
How do you break a string up into an array?
String.split( )
45
Do string methods change the original string? How would you check if you weren't sure?
No, string are immutable. Console log.
46
Roughly how many string methods are there according to the MDN Web docs?
36.
47
Roughly how many array methods are there according to the MDN Web docs?
35.
48
Is the return value of a function or method useful in every situation?
No.
49
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
50
How do you remove the last element from an array?
Array.pop( )
51
Give 6 examples of comparison operators.
==, !=, ===, , >=, <=
52
What data type do comparison expressions evaluate to?
Boolean.
53
What is the purpose of an if statement?
To make a decision
54
Is else required in order to use an if statement?
No.
55
Describe the syntax (structure) of an if statement.
if (condition){ code to be exectuted; }
56
What are the three logical operators?
logical And (&&), Logical Or ( || ), Logical Not ( ! )
57
How do you compare two different expressions in the same condition?
&& or | |
58
What is the purpose of a loop?
Repeat code until condition is met.
59
What is the purpose of a condition expression in a loop?
To tell the loop when to stop running.
60
What does "iteration" mean in the context of loops?
One full pass of the loops code block.
61
When does the condition expression of a while loop get evaluated?
Before each Iteration.
62
When does the initialization expression of a for loop get evaluated?
Once, before the loop begins.
63
When does the condition expression of a for loop get evaluated?
After the final expression and before each iteration.
64
When does the final expression of a for loop get evaluated?
After each iteration.
65
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
Break.
66
What does the ++ increment operator do?
Increments by 1.
67
How do you iterate through the keys of an object?
For in loop.
68
What event is fired when a user places their cursor in a form control?
Focus event
69
What event is fired when a user's cursor leaves a form control?
Blur event
70
What event is fired as a user changes the value of a form control?
Input event
71
What event is fired when a user clicks the "submit" button within a ?
Submit event
72
What does the event.preventDefault() method do?
Prevents the page from automatically reloading.
73
What does submitting a form without event.preventDefault() do?
Refreshes the page.
74
What property of a form element object contains all of the form's controls.
Elements property.
75
What property of form a control object gets and sets its value?
Value property.
76
What is one risk of writing a lot of code without checking to see if it works so far?
There may have been an error that you didn't notice and have to re write the code.
77
What is the event.target?
The element on which the event occurred.
78
What is the affect of setting an element to display: none?
Hides the element from the page.
79
What does the element.matches() method take as an argument and what does it return?
CSS selector and returns a boolean value.
80
How can you retrieve the value of an element's attribute?
getAttribute( )
81
At what steps of the solution would it be helpful to log things to the console?
Every step.
82
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?
Every element would have an event listener on it.
83
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?
With multiple if statements.
84
What is JSON?
A data interchange format.
85
What are serialization and deserialization?
Serialization - turning an object into bytes. Deserialization - turning bytes into an object.
86
Why are serialization and deserialization useful?
To send data over a network.
87
How do you serialize a data structure into a JSON string using JavaScript?
JSON.stringify( )
88
How do you deserialize a JSON string into a data structure using JavaScript?
JSON.parse( )
89
How do you store data in localStorage?
localStorage.setItem( )
90
How do you retrieve data from localStorage?
localStorage.getItem( )
91
What data type can localStorage save in the browser?
Strings.
92
When does the 'beforeunload' event fire on the window object?
Closing tab or refreshing page.
93
What is a method?
A function that is a property of an object.
94
How can you tell the difference between a method definition and a method call?
Definition is a function. being assigned to a property. Call is methodName.property( ).
95
Describe method definition syntax (structure).
property: function (optional parameters)
96
Describe method call syntax (structure).
Object.methodName( )
97
How is a method different from any other function?
Method is attached to an object. Function is on its own.
98
What are the four "principles" of Object-Oriented Programming?
Abstraction, Encapsulation, Inheritance, Polymorphism.
99
What is "abstraction"?
Working with complex things in a simple way.
100
What does API stand for?
application programming interface
101
What is the purpose of an API?
Allows computers to communicate to each other.
102
What is this in JavaScript?
A variable that holds a value which is the name of the object you are working in.
103
What does it mean to say that this is an "implicit parameter"?
It is available in a functions code block even though it was never included in the functions parameter list or declared with var.
104
When is the value of this determined in a function; call time or definition time?
Call time.
105
How can you tell what the value of this will be for a particular function or method definition?
You don't know what the value will be.
106
How can you tell what the value of this is for a particular function or method call?
the object to the left of the dot or the global window object.
107
What kind of inheritance does the JavaScript programming language use?
Prototypal Inheritance.
108
What is a prototype in JavaScript?
an object that contains properties and methods that can be used by other objects.
109
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?
They look for the prototype.
110
If an object does not have it's own property or method by a given key, where does JavaScript look for it?
On the prototype.
111
What does the new operator do?
Creates a blank object, adds a property to the new object (proto), binds the newly created object instance as this, returns this if the function doesn't return an object.
112
What property of JavaScript functions can store shared behavior for instances created with new?
Prototype.
113
What does the instanceof operator do?
Checks if the prototype property of a constructor appears in the prototype chain of an object.
114
What is a "callback" function?
A function that is passed into another function as an argument.
115
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?
setTimeout( )
116
How can you set up a function to be called repeatedly without using a loop?
setInterval( )
117
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0
118
What do setTimeout() and setInterval() return?
A numeric Id.
119
What is a client?
A piece of computer hardware or software asks for something.
120
What is a server?
A piece of computer hardware or software that gives a response to the client.
121
Which HTTP method does a browser issue to a web server when you visit a URL?
GET
122
What three things are on the start-line of an HTTP response message?
Protocol version, status code, and status text.
123
What are HTTP headers?
lets the client and the server pass additional information with an HTTP request or response
124
Where would you go if you wanted to learn more about a specific HTTP Header?
MDN
125
Is a body required for a valid HTTP request or response message?
No.
126
What is AJAX?
It allows users to still use the page while requests are being made.
127
What does the AJAX acronym stand for?
Asynchronous Javascript and XML.
128
Which object is built into the browser for making HTTP requests in JavaScript?
XMLHttpRequest
129
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
load
130
An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?
receiving the response is an event and event targets include objects that support events.
131
An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?
They share prototype.
132
What is a code block? What are some examples of a code block?
Inside of curly braces. Function code block, conditional code block, for loop code block...
133
What does block scope mean?
Variable only exists within the code block.
134
What is the scope of a variable declared with const or let?
Block scoped.
135
What is the difference between let and const?
Let can be reassigned and Const cannot be reassigned.
136
Why is it possible to .push() a new value into a const variable that points to an Array?
You can change the arrays elements but not reassign the array to another array.
137
How should you decide on which type of declaration to use?
If you know you will not change the value of the variable, use Const. Use, Let when you need to change a value of a variable.
138
What is the syntax for writing a template literal?
Wrap text in back-ticks. variables are in ${var}.
139
What is "string interpolation"?
Placing variables and expressions within the string and Javascript will replace them with their values.
140
What is destructuring, conceptually?
Unpacking values from arrays or properties of an objects into variables.
141
What is the syntax for Object destructuring?
const keyword {property names} = object variable name
142
What is the syntax for Array destructuring?
const keyword [index#/var names] = array variable name
143
How can you tell the difference between destructuring and creating Object/Array literals?
Placements of the brackets in respect to destructuring or creating.
144
What is the syntax for defining an arrow function?
var keyword functionName = (parameters) => expression
145
When an arrow function's body is left without curly braces, what changes in its functionality?
There can only be an expression (no statements).
146
How is the value of this determined within an arrow function?
The value of this is inherited from the surrounding scope it was defined in.
147
What is a CLI?
Command line interface
148
What is a GUI?
Graphical user interface
149
Give at least one use case for each of the commands listed in this exercise.
``` man - checking manual cat - Concatenates files / Prints contents of file. ls - check list of contents in directory pwd - verify the current directory you are in echo - Displays line of text touch - Changes file timestamps. mkdir - Create new directory mv - rename directories and moves them. rm - delete file or directory cp - Copy a file ```
150
What is Node.js?
A program that allows Js to be run outside of a browser.
151
What are the three states a Promise can be in?
Pending, fulfilled, rejected
152
How do you handle the fulfillment of a Promise?
then method (function)
153
How do you handle the rejection of a Promise?
catch()
154
What is Array.prototype.filter useful for?
Getting rid of elements in array that do not pass the test in the function / finding certain elements
155
What is Array.prototype.map useful for?
Calling a function for each element in the array
156
What is Array.prototype.reduce useful for?
Combine elements of an array to a single value
157
What is "syntactic sugar"?
A way of writing code in a way that is easier to read or express that, if removed, would not effect the language functionality
158
What is the typeof an ES6 class?
checks if the class is a function
159
Describe ES6 class syntax.
``` class keyword functionName{ constructor(name){ this.name = name } } ```
160
What is "refactoring"?
Restructuring existing code without changing its behavior
161
What does fetch() return?
A promise
162
What is the default request method used by fetch()?
GET
163
How do you specify the request method (GET, POST, etc.) when calling fetch?
fetch(url, object with method property with value set to which method you are using)
164
When does React call a component's componentDidMount method?
Immediately after a component is rendered for the first successful render
165
Name three React.Component lifecycle methods.
Constructor, Render, componentDidMount
166
How do you pass data to a child component?
props
167
In JavaScript, when is a function's scope determined; when it is called or when it is defined?
when it is defined.
168
What allows JavaScript functions to "remember" values from their surroundings?
closures - lexical scoping. Inner function have access to variables declared in their outer scope.