Javascript Flashcards

1
Q

What is the purpose of variables?

A

To store values within them

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, let or const followed by variable 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

Assignment operator =

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, 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

Calling on the variable will require matching the case of all letters exactly

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

Represents letters

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 numerical 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

Represents true or false, 1 or 0

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

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

variable = new 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 means there is no value whereas undefined means the value is not declared yet

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

To see what you are logging

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

What is string concatenation?

A

Combining multiple string inputs

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

To concatenate strings or to add numbers

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

Boolean values

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

Add and assign

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

What are objects used for?

A

To group variables and functions

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

What are object properties?

A

Keys and values

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

Describe object literal notation.

A

Declare variable = {key: value, key: value}

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

How do you remove a property from an object?

A

delete object.key

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

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

A

Dot or bracket notation, pair with assignment operator if updating

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

What are arrays used for?

A

To have a list of items

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

Describe array literal notation.

A

array name = [item, item, item];

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

How are arrays different from “plain” objects?

A

Uses brackets rather than curly braces, and indexes rather than keys

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

What is the length property of an array?

A

array.length
Returns total length of the array or total number of items within the list

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

How do you calculate the last index of an array?

A

array.length - 1

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

What is a function in JavaScript?

A

A block of code that can be called on and executed

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

Describe the parts of a function definition.

A

function declaration, name, parameters, function code block

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

Describe the parts of a function call.

A

function name (argument)

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

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

A

Function definition will have “function” prior to the function name. Function call may include arguments whereas definition would have parameters

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

What is the difference between a parameter and an argument?

A

Parameters are placeholders whereas arguments are the actual data we want to use

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

Why are function parameters useful?

A

They act as placeholders that can be referenced within the function code block

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

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

A

Produces a value, exits the function

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

Why do we log things to the console?

A

To check our results

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

What is a method?

A

A function that is a property of an object

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

How is a method different from any other function?

A

It is property of an object. Functions don’t have a dynamic “this” binding

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

How do you remove the last element from an array?

A

.pop() method

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

How do you round a number down to the nearest integer?

A

.floor() method

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

How do you generate a random number?

A

Math.random() method

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

How do you delete an element from an array?

A

.pop(), .shift(), .splice()

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

How do you append an element to an array?

A

.push(), .unshift()

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

How do you break a string up into an array?

A

.split() method

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

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

A

No they are not referenced data types. They are immutable. You can check using console.log()

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

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

A

50

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

Is the return value of a function or method useful in every situation?

A

No, some returned values may be created to be used at a later time or we may just want it to execute an action without returning the results

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

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

A

40-50

50
Q

What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?

A

MDN

51
Q

Give 6 examples of comparison operators.

A

<, >, ===, >=, <=, ==

52
Q

What data type do comparison expressions evaluate to?

A

Boolean

53
Q

What is the purpose of an if statement?

A

To create a condition for executing code

54
Q

Is else required in order to use an if statement?

A

No

55
Q

Describe the syntax (structure) of an if statement.

A

if(condition){
code
}

56
Q

What are the three logical operators?

A

&&, ||, !

57
Q

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

A

Enclose each expression in parentheses and use an and/or operator

58
Q

What is the purpose of a loop?

A

To execute code repeatedly until condition is met or code is broken

59
Q

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

A

To define a stopping point for the loop or whether code should be executed

60
Q

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

A

Each cycle of the loop

61
Q

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

A

At the beginning of each iteration

62
Q

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

A

Once before the loop begins

63
Q

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

A

At the start of each iteration

64
Q

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

A

At the end of each iteration

65
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

66
Q

What does the ++ increment operator do?

A

Increase the variable by 1 and reassign the new value to the variable

67
Q

How do you iterate through the keys of an object?

A

for (let key in object)

68
Q

What is JSON?

A

String/Text-based data format that follows JavaScript object syntax

69
Q

What are serialization and deserialization?

A

Serialization is turning objects into a string. Deserialization is the reverse where you convert a string into an object in memory

70
Q

Why are serialization and deserialization useful?

A

They help us store and transmit data to and from servers/devices, and begin to collect/modify data again. They also give us an object that can be used across various languages

71
Q

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

A

JSON.stringify()

72
Q

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

A

JSON.parse()

73
Q

How do you store data in localStorage?

A

localStorage.setItem(key, value)

74
Q

How do you retrieve data from localStorage?

A

localStorage.getItem(key)

75
Q

What data type can localStorage save in the browser?

A

JSON string

76
Q

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

A

When the window is in the process of being closed/refreshed and the DOM is cleared

77
Q

What is a method?

A

A method is a function that is a property of an object

78
Q

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

A

A definition will be a property with a function assigned to it, whereas a method call will be the object name with the property called on it and ()

79
Q

Describe method definition syntax (structure).

A

methodName: function () { example function }

80
Q

Describe method call syntax (structure).

A

object.method()

81
Q

How is a method different from any other function?

A

It is a property of an object

82
Q

What is the defining characteristic of Object-Oriented Programming?

A

It contains data as properties and behavior as methods

83
Q

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

A

Abstraction, encapsulation, inheritance, polymorphism

84
Q

What is “abstraction”?

A

Being able to work on complex things in simple ways

85
Q

What does API stand for?

A

Application programming interface

86
Q

What is the purpose of an API?

A

To allow multiple programs to communicate with each other

87
Q

What is this in JavaScript?

A

An implicit parameter of all JS functions. It refers to the calling object; if none, it refers to the window object

88
Q

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

A

It is used in the code block but not called out as a parameter or declared

89
Q

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

A

Call time

90
Q

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

A

You can’t tell until it is being called on

91
Q

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

A

By looking at the property & object being called on the ‘this’ parameter

92
Q

What kind of inheritance does the JavaScript programming language use?

A

Prototype-based inheritance

93
Q

What is a prototype in JavaScript?

A

An object with certain behaviors (methods) or data (properties) that can used by other objects

94
Q

How is it possible to call methods on strings, arrays, and numbers even though those methods don’t actually exist on strings, arrays, and numbers?

A

They have stored prototypes that automatically come with JavaScript

95
Q

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

A

In the object prototype

96
Q

What kind of inheritance does the JavaScript programming language use?

A

Prototype-based inheritance or prototypal inheritance

97
Q

What is a prototype in JavaScript?

A

An object contains the functionality that you want to prototype on other objects. Or, an object with certain behaviors (methods) or data (properties) that can used by other objects

98
Q

How is it possible to call methods on strings, arrays, and numbers even though those methods don’t actually exist on strings, arrays, and numbers?

A

They inherit it from stored prototypes that automatically come with JavaScript

99
Q

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

A

In the object prototype chain

100
Q

What does the new operator do?

A
  1. Creates a blank JS object
  2. Points the new instance’s prototype to the constructor function’s prototype
  3. Execute the constructor function and ties ‘this’ to the new object
  4. If the object returns a non-primitive, then the return value will become the result of the new expression
    - Primitives are boolean, string, numbers, undefined
    - Non-primitives are everything else
101
Q

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

A

Prototype

102
Q

What does the instanceof operator do?

A

Returns a boolean on whether the object’s prototype chain includes the specified constructor

103
Q

What is a “callback” function?

A

A function passed into another function as an argument

104
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() - this will allow you to delay the code and have it executed once

105
Q

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

A

setInterval() - in contrast to setTimeout(), the setInterval() function will repeat the code until it is stopped

106
Q

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

A

0

107
Q

What do setTimeout() and setInterval() return?

A

A numeric timeout or interval ID to identify the timer/interval

108
Q

What is a client?

A

The server requester of information

109
Q

What is a server?

A
  • A device that provides a service to another computer
  • A resource or service provider
110
Q

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

A

Get

111
Q

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

A
  • HTTP method, a verb (GET, PUT, POST) or noun (HEAD, OPTIONS)
  • Request target (URLs) and domain
  • HTTP version to define structure of remaining message
112
Q

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

A

Protocol version, status code, status text

113
Q

What are HTTP headers?

A
  • case-insensitive name followed by colon : and its value
  • Communicates to client and server what information to pass
114
Q

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

A

MDN

115
Q

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

A

No, it will depend on the response

116
Q

What is AJAX?

A

An asynchronous processing technique used to request and load data from a server without reloading a 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

new XMLHttpRequest()

119
Q

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

A

load or onload

120
Q

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

A

Prototype inheritance. An XMLHttpRequest is an object that supports events, therefore, able to have this functionality