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
Q

How are arrays different from “plain” objects?

A
  • Numerical Indexes
  • Ordered
  • Special methods to modify array values (push, pop, shift, unshift, splice, etc)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
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
27
Q

What is the length property of an array?

A

Returns the number of array entries

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

How do you calculate the last index of an array?

A

arr[arr.length – 1]

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

What is a function in JavaScript?

A

A set of reusable code

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

Describe the parts of a function definition.

A

let endOfSentence = ‘something’

function example (params) {
   return 'I am returning ' + params;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

Describe the parts of a function call.

A

example(endOfSentence)

“I am returning something”

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

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

A

Function call:

  • No code block
  • arguments

Function Definition:

  • function keyword
  • Code block
  • return statement
  • parameters
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

What is the difference between a parameter and an argument?

A

Parameter exist in function definitions and are placeholders (variables)

Argument are passed into a function’s parameters in a function call as values

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

Why are function parameters useful?

A

Allow for dynamic data and reusability

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

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

A

Returns the output of the function

Immediately exits the function

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

How is a method different from any other function?

A

Methods are attached to objects

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

How do you remove the last element from an array?

A

array.pop()

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

How do you delete an element from an array?

A

array. splice(start index, [delete count], [replacement]);

array. spice(3, 1)

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

How do you append an element to an array?

A

array.push();

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

How do you break a string up into an array?

A

string.split();

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

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

A

String methods DO NOT change the original string

Check by console.log the original string after using the method

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

Give 6 examples of comparison operators.

A
> (gt)
 < (lt)
<= (lte) 
>= (gte) 
=== (strictly equal) 
!== (not strictly equal)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
46
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
47
Q

What is the purpose of an if statement?

A

Take decisions on code based on if a specified condition is truthy, if falsy the else block can run

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

Describe the syntax (structure) of an if statement.

A
if (condition) {
  //code block to run if condition is met
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
50
Q

What are the three logical operators?

A

&& (and)
|| (or)
! (not)

51
Q

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

A

|| (or)

&& (and)

52
Q

What is the purpose of a loop?

A

To automate tasks to a set end point determined by a condition

53
Q

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

A

The condition expressions tells the loop when to stop

54
Q

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

A

Iteration refers to when the code inside the curly braces run

55
Q

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

A

Prior to each pass through the loop

56
Q

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

A

Before anything

57
Q

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

A

Before each loop iteration

58
Q

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

A

End of each iteration, and before evaluation

59
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 statement

60
Q

What does the ++ increment operator do?

A

Adds one, after the value is read

61
Q

How do you iterate through the keys of an object?

A

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
Q

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

A

Focus

63
Q

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

A

Blur

64
Q

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

A

Input

65
Q

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

A

Submit

66
Q

What does the event.preventDefault() method do?

A

Prevents the event’s default behavior

67
Q

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

A

Reloads the page

68
Q

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

A

$form.elements

69
Q

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

A

event.target.value

70
Q

What is the event.target?

A

The node of where the event occurred

71
Q

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

A

Removes element from the document flow

72
Q

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

A

Argument: CSS selector

Returns Boolean

73
Q

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

A

$element.getAttribute(“attrName”)

74
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

Multiple event listeners addressing each tab and view

75
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

Multiple conditions for the various indexes

76
Q

What is JSON?

A

Text-based data format following the object syntax that can be independently created and stored apart from JavaScript.

77
Q

What are serialization and deserialization?

A

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
Q

Why are serialization and deserialization useful?

A

It allows developers to share and store data

79
Q

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

A

JSON.parse()

80
Q

How to you store data in localStorage?

A

localStorage.setItem(‘keyName’, keyValue);

81
Q

How to you retrieve data from localStorage?

A

var item = localStorage.getItem(‘keyName’);

82
Q

What data type can localStorage save in the browser?

A

String

83
Q

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

A

Before the user navigates away from the page, or reloads the page

84
Q

What is a method?

A

A method is a function which is a property of an object.

85
Q

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

A

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
Q

Describe method definition syntax (structure).

A

Method name & Colon
Function keyword & Optional parameters
Code block with return statement
Comma (if following methods or properties)

87
Q

Describe method call syntax (structure).

A

Method name of the object with zero or more arguments

object.method()

88
Q

How is a method different from any other function?

A

A method is different from any other function because it exists within the object’s scope

89
Q

What is the defining characteristic of Object-Oriented Programming?

A

Objects that can hold data and behavior

90
Q

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

A

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
Q

What is “abstraction”?

A

The omission of complex functionality or details to simplify and create further emphasis on other things that may be more important.

92
Q

What does API stand for?

A

Application Programming Interface – the connection between computers or between computer programs.

93
Q

What is the purpose of an API?

A

Abstract information of how a system works, and only showing relevant information for the programmer

94
Q

What is this in JavaScript?

A

“This” is a keyword implicit parameter that refers to the object it’s within at call time

95
Q

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

A

“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
Q

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

A

Call time

97
Q

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

A

If you cannot see the function being called, then you do not know what the value of “this” will be

98
Q

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

A

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
Q

What kind of inheritance does the JavaScript programming language use?

A

Prototypal inheritance

100
Q

What is a prototype in JavaScript?

A

The original template object that other objects can inherits methods and properties from

101
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

It is included in the data type’s prototype

102
Q

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

A

Looks into the object’s prototype

103
Q

What does the new operator do for an Object constructor?

A
  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
Q

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

A

Prototype property

105
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. The return value is a boolean value.

106
Q

What is a “callback” function?

A

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
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() function will delay execution based on the milliseconds, added as second argument

108
Q

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

A

setInterval() can be used to repeatedly call without a loop

109
Q

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

A

0

110
Q

What do setTimeout() and setInterval() return?

A

timeoutId

intervalId

111
Q

What is a client?

A

A requester of a service

112
Q

What is a server?

A

The providers of a resource or service

Always waiting for client requests

113
Q

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

A

GET method

114
Q

What three things are on the start-line of an HTTP request message?

A
  • 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
Q

What three things are on the start-line of an HTTP response message?

A

Status Line

  • Protocol version (HTTP/1.1)
  • Status Code (success or failure codes)
  • Status text (HTTP/1.1 404 Not Found.)
116
Q

What are HTTP headers?

A

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

117
Q

Where would you go if you wanted to learn more about a specific HTTP Header?

A

MDN docs on HTTP Headers

118
Q

Is a body required for a valid HTTP request or response message?

A

No

119
Q

What is AJAX?

A

The use of XMLHttpRequest to communicate with servers to send or retrieve data

120
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript and XML

121
Q

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

A

XMLHttpRequest Object

122
Q

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

A

Load event

123
Q

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

A

They both have the EventTarget prototype that contains the addEventListener method