JavaScript ES5 Flashcards

1
Q

What is the purpose of variables?

A

Store data for future access

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

How do you declare a variable?

A

var quantity;

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

quantity = 3;

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

Letters
Numbers (cannot start with)
$
_

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

Variables are stored with case sensitive 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

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

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

Used with conditional logic to run specific blocks of code

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 values to variables

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

let quantity = 3;

//reassign
quantity = 7;
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:
a non-existent value that is intentionally assigned by the user, usually a placeholder value

undefined:
a non-existent value that is automatically assigned by JavaScript if no value is given

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

Give five examples of JavaScript primitives.

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

What is string concatenation?

A

Combination of at least one string value with another string value or primitive value

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

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

A

Addition

Concatenation

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

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

A

Addition Assignment:

Adds the left value with the right value, and the result of this expression is reassigned to the left

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

What are objects used for?

A

Encapsulating characteristic data by key value pairs

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

What are object properties?

A

Variables inside of an object

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

Describe object literal notation.

A

var obj = {};

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

How do you remove a property from an object?

A

delete hotel.booked;

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

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

A

Dot Notation:
vehicle.color = black

Bracket Notation:
vehicle[“color”] = “black”

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

What are arrays used for?

A

Store a list of numerically, zero based indexed data, where order may matter

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

Describe array literal notation.

A

var array = [];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
How are arrays different from "plain" objects?
- Numerical Indexes - Ordered - Special methods to modify array values (push, pop, shift, unshift, splice, etc)
26
What number represents the first index of an array?
0
27
What is the length property of an array?
Returns the number of array entries
28
How do you calculate the last index of an array?
arr[arr.length – 1]
29
What is a function in JavaScript?
A set of reusable code
30
Describe the parts of a function definition.
let endOfSentence = 'something' ``` function example (params) { return 'I am returning ' + params; } ```
31
Describe the parts of a function call.
example(endOfSentence) "I am returning something"
32
When comparing them side-by-side, what are the differences between a function call and a function definition?
Function call: - No code block - arguments Function Definition: - function keyword - Code block - return statement - parameters
33
What is the difference between a parameter and an argument?
Parameter exist in function definitions and are placeholders (variables) Argument are passed into a function's parameters in a function call as values
34
Why are function parameters useful?
Allow for dynamic data and reusability
35
What two effects does a return statement have on the behavior of a function?
Returns the output of the function | Immediately exits the function
36
How is a method different from any other function?
Methods are attached to objects
37
How do you remove the last element from an array?
array.pop()
38
How do you round a number down to the nearest integer?
Math.floor();
39
How do you generate a random number?
Math.random();
40
How do you delete an element from an array?
array. splice(start index, [delete count], [replacement]); | array. spice(3, 1)
41
How do you append an element to an array?
array.push();
42
How do you break a string up into an array?
string.split();
43
Do string methods change the original string? How would you check if you weren't sure?
String methods DO NOT change the original string Check by console.log the original string after using the method
44
Is the return value of a function or method useful in every situation?
No
45
Give 6 examples of comparison operators.
``` > (gt) < (lt) <= (lte) >= (gte) === (strictly equal) !== (not strictly equal) ```
46
What data type do comparison expressions evaluate to?
Boolean
47
What is the purpose of an if statement?
Take decisions on code based on if a specified condition is truthy, if falsy the else block can run
48
Is else required in order to use an if statement?
No
49
Describe the syntax (structure) of an if statement.
``` if (condition) { //code block to run if condition is met } ```
50
What are the three logical operators?
&& (and) || (or) ! (not)
51
How do you compare two different expressions in the same condition?
|| (or) | && (and)
52
What is the purpose of a loop?
To automate tasks to a set end point determined by a condition
53
What is the purpose of a condition expression in a loop?
The condition expressions tells the loop when to stop
54
What does "iteration" mean in the context of loops?
Iteration refers to when the code inside the curly braces run
55
When does the condition expression of a while loop get evaluated?
Prior to each pass through the loop
56
When does the initialization expression of a for loop get evaluated?
Before anything
57
When does the condition expression of a for loop get evaluated?
Before each loop iteration
58
When does the final expression of a for loop get evaluated?
End of each iteration, and before evaluation
59
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
Break statement
60
What does the ++ increment operator do?
Adds one, after the value is read
61
How do you iterate through the keys of an object?
for in statement: e.g. for(var key in object) Get Values: Insert the variable in brackets pointing at the object e.g. object[variable]
62
What event is fired when a user places their cursor in a form control?
Focus
63
What event is fired when a user's cursor leaves a form control?
Blur
64
What event is fired as a user changes the value of a form control?
Input
65
What event is fired when a user clicks a button type "submit" within a form?
Submit
66
What does the event.preventDefault() method do?
Prevents the event's default behavior
67
What does submitting a form without event.preventDefault() do?
Reloads the page
68
What property of a form element object contains all of the form's controls.
$form.elements
69
What property of a form control object gets and sets its value?
event.target.value
70
What is the event.target?
The node of where the event occurred
71
What is the affect of setting an element to display: none?
Removes element from the document flow
72
What does the element.matches() method take as an argument and what does it return?
Argument: CSS selector | Returns Boolean
73
How can you retrieve the value of an element's attribute?
$element.getAttribute("attrName")
74
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?
Multiple event listeners addressing each tab and view
75
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?
Multiple conditions for the various indexes
76
What is JSON?
Text-based data format following the object syntax that can be independently created and stored apart from JavaScript.
77
What are serialization and deserialization?
Serialization is the process of converting an object to a stream of bytes so it can be stored or sent over the network (back end for example). Deserialization is the process of converting the stream of bytes back into an object in memory.
78
Why are serialization and deserialization useful?
It allows developers to share and store data
79
How do you deserialize a JSON string into a data structure using JavaScript?
JSON.parse()
80
How to you store data in localStorage?
localStorage.setItem('keyName', keyValue);
81
How to you retrieve data from localStorage?
var item = localStorage.getItem('keyName');
82
What data type can localStorage save in the browser?
String
83
When does the 'beforeunload' event fire on the window object?
Before the user navigates away from the page, or reloads the page
84
What is a method?
A method is a function which is a property of an object.
85
How can you tell the difference between a method definition and a method call?
How can you tell the difference between a method definition and a method call? ``` Method Definition: function keyword, code block ``` Method Call: object.method()
86
Describe method definition syntax (structure).
Method name & Colon Function keyword & Optional parameters Code block with return statement Comma (if following methods or properties)
87
Describe method call syntax (structure).
Method name of the object with zero or more arguments object.method()
88
How is a method different from any other function?
A method is different from any other function because it exists within the object’s scope
89
What is the defining characteristic of Object-Oriented Programming?
Objects that can hold data and behavior
90
What are the four "pillars" of Object-Oriented Programming?
Abstraction - the concept of wrapping up complex actions in simple methods Encapsulation - keep state and logic internal Inheritance - Classes can have parent classes. Child classes will inherit all of the behavior and attributes of the parent class Polymorphism - we can call the same method on different objects
91
What is "abstraction"?
The omission of complex functionality or details to simplify and create further emphasis on other things that may be more important.
92
What does API stand for?
Application Programming Interface – the connection between computers or between computer programs.
93
What is the purpose of an API?
Abstract information of how a system works, and only showing relevant information for the programmer
94
What is this in JavaScript?
“This” is a keyword implicit parameter that refers to the object it’s within at call time
95
What does it mean to say that this is an "implicit parameter"?
“this” is available in a function's code block even though it was never included in the function's parameter list or declared with var.
96
When is the value of this determined in a function; call time or definition time?
Call time
97
How can you tell what the value of this will be for a particular function or method definition?
If you cannot see the function being called, then you do not know what the value of "this" will be
98
How can you tell what the value of this is for a particular function or method call?
Method: this will refer to the object at the left of the dot at call time. Function: this will refer to the window if there is no dot or object at call time
99
What kind of inheritance does the JavaScript programming language use?
Prototypal inheritance
100
What is a prototype in JavaScript?
The original template object that other objects can inherits methods and properties from
101
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?
It is included in the data type's prototype
102
If an object does not have it's own property or method by a given key, where does JavaScript look for it?
Looks into the object's prototype
103
What does the new operator do for an Object constructor?
1. Creates empty object 2. Binds __proto__ to the new instance 3. Binds “this” to the newly created object 4. Returns this if the function doesn’t return an object
104
What property of JavaScript functions can store shared behavior for instances created with new?
Prototype property
105
What does the instanceof operator do?
The instanceof operator tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object. The return value is a boolean value.
106
What is a "callback" function?
A callback function is a function which is: - accessible by another function, and - is invoked after the first function if that first function completes
107
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() function will delay execution based on the milliseconds, added as second argument
108
How can you set up a function to be called repeatedly without using a loop?
setInterval() can be used to repeatedly call without a loop
109
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0
110
What do setTimeout() and setInterval() return?
timeoutId | intervalId
111
What is a client?
A requester of a service
112
What is a server?
The providers of a resource or service Always waiting for client requests
113
Which HTTP method does a browser issue to a web server when you visit a URL?
GET method
114
What three things are on the start-line of an HTTP request message?
- HTTP method (GET, PUT, POST, HEAD, OPTIONS) - Request Target (usually URL, or absolute path) - Protocol version (indicator of the expected version to use for the response)
115
What three things are on the start-line of an HTTP response message?
Status Line - Protocol version (HTTP/1.1) - Status Code (success or failure codes) - Status text (HTTP/1.1 404 Not Found.)
116
What are HTTP headers?
HTTP headers let the client and the server pass additional information with an HTTP request or response.
117
Where would you go if you wanted to learn more about a specific HTTP Header?
MDN docs on HTTP Headers
118
Is a body required for a valid HTTP request or response message?
No
119
What is AJAX?
The use of XMLHttpRequest to communicate with servers to send or retrieve data
120
What does the AJAX acronym stand for?
Asynchronous JavaScript and XML
121
Which object is built into the browser for making HTTP requests in JavaScript?
XMLHttpRequest Object
122
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
Load event
123
An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?
They both have the EventTarget prototype that contains the addEventListener method