Javascript Flashcards

(120 cards)

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
Describe array literal notation.
array name = [item, item, item];
26
How are arrays different from "plain" objects?
Uses brackets rather than curly braces, and indexes rather than keys
27
What number represents the first index of an array?
0
28
What is the length property of an array?
array.length Returns total length of the array or total number of items within the list
29
How do you calculate the last index of an array?
array.length - 1
30
What is a function in JavaScript?
A block of code that can be called on and executed
31
Describe the parts of a function definition.
function declaration, name, parameters, function code block
32
Describe the parts of a function call.
function name (argument)
33
When comparing them side-by-side, what are the differences between a function call and a function definition?
Function definition will have “function” prior to the function name. Function call may include arguments whereas definition would have parameters
34
What is the difference between a parameter and an argument?
Parameters are placeholders whereas arguments are the actual data we want to use
35
Why are function parameters useful?
They act as placeholders that can be referenced within the function code block
36
What two effects does a return statement have on the behavior of a function?
Produces a value, exits the function
37
Why do we log things to the console?
To check our results
38
What is a method?
A function that is a property of an object
39
How is a method different from any other function?
It is property of an object. Functions don’t have a dynamic "this" binding
40
How do you remove the last element from an array?
.pop() method
41
How do you round a number down to the nearest integer?
.floor() method
42
How do you generate a random number?
Math.random() method
43
How do you delete an element from an array?
.pop(), .shift(), .splice()
44
How do you append an element to an array?
.push(), .unshift()
45
How do you break a string up into an array?
.split() method
46
Do string methods change the original string? How would you check if you weren't sure?
No they are not referenced data types. They are immutable. You can check using console.log()
47
Roughly how many string methods are there according to the MDN Web docs?
50
48
Is the return value of a function or method useful in every situation?
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
49
Roughly how many array methods are there according to the MDN Web docs?
40-50
50
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
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 create a condition for executing code
54
Is else required in order to use an if statement?
No
55
Describe the syntax (structure) of an if statement.
if(condition){ code }
56
What are the three logical operators?
&&, ||, !
57
How do you compare two different expressions in the same condition?
Enclose each expression in parentheses and use an and/or operator
58
What is the purpose of a loop?
To execute code repeatedly until condition is met or code is broken
59
What is the purpose of a condition expression in a loop?
To define a stopping point for the loop or whether code should be executed
60
What does "iteration" mean in the context of loops?
Each cycle of the loop
61
When does the condition expression of a while loop get evaluated?
At the beginning of 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?
At the start of each iteration
64
When does the final expression of a for loop get evaluated?
At the end of 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?
Increase the variable by 1 and reassign the new value to the variable
67
How do you iterate through the keys of an object?
for (let key in object)
68
What is JSON?
String/Text-based data format that follows JavaScript object syntax
69
What are serialization and deserialization?
Serialization is turning objects into a string. Deserialization is the reverse where you convert a string into an object in memory
70
Why are serialization and deserialization useful?
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
How do you serialize a data structure into a JSON string using JavaScript?
JSON.stringify()
72
How do you deserialize a JSON string into a data structure using JavaScript?
JSON.parse()
73
How do you store data in localStorage?
localStorage.setItem(key, value)
74
How do you retrieve data from localStorage?
localStorage.getItem(key)
75
What data type can localStorage save in the browser?
JSON string
76
When does the 'beforeunload' event fire on the window object?
When the window is in the process of being closed/refreshed and the DOM is cleared
77
What is a method?
A method is a function that is a property of an object
78
How can you tell the difference between a method definition and a method call?
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
Describe method definition syntax (structure).
methodName: function () { example function }
80
Describe method call syntax (structure).
object.method()
81
How is a method different from any other function?
It is a property of an object
82
What is the defining characteristic of Object-Oriented Programming?
It contains data as properties and behavior as methods
83
What are the four "principles" of Object-Oriented Programming?
Abstraction, encapsulation, inheritance, polymorphism
84
What is "abstraction"?
Being able to work on complex things in simple ways
85
What does API stand for?
Application programming interface
86
What is the purpose of an API?
To allow multiple programs to communicate with each other
87
What is this in JavaScript?
An implicit parameter of all JS functions. It refers to the calling object; if none, it refers to the window object
88
What does it mean to say that this is an "implicit parameter"?
It is used in the code block but not called out as a parameter or declared
89
When is the value of this determined in a function: call time or definition time?
Call time
90
How can you tell what the value of this will be for a particular function or method definition?
You can't tell until it is being called on
91
How can you tell what the value of this is for a particular function or method call?
By looking at the property & object being called on the ‘this’ parameter
92
What kind of inheritance does the JavaScript programming language use?
Prototype-based inheritance
93
What is a prototype in JavaScript?
An object with certain behaviors (methods) or data (properties) that can used by other objects
94
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?
They have stored prototypes that automatically come with JavaScript
95
If an object does not have its own property or method by a given key, where does JavaScript look for it?
In the object prototype
96
What kind of inheritance does the JavaScript programming language use?
Prototype-based inheritance or prototypal inheritance
97
What is a prototype in JavaScript?
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
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?
They inherit it from stored prototypes that automatically come with JavaScript
99
If an object does not have its own property or method by a given key, where does JavaScript look for it?
In the object prototype chain
100
What does the new operator do?
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
What property of JavaScript functions can store shared behavior for instances created with new?
Prototype
102
What does the instanceof operator do?
Returns a boolean on whether the object’s prototype chain includes the specified constructor
103
What is a "callback" function?
A function passed into another function as an argument
104
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() - this will allow you to delay the code and have it executed once
105
How can you set up a function to be called repeatedly without using a loop?
setInterval() - in contrast to setTimeout(), the setInterval() function will repeat the code until it is stopped
106
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0
107
What do setTimeout() and setInterval() return?
A numeric timeout or interval ID to identify the timer/interval
108
What is a client?
The server requester of information
109
What is a server?
- A device that provides a service to another computer - A resource or service provider
110
Which HTTP method does a browser issue to a web server when you visit a URL?
Get
111
What three things are on the start-line of an HTTP request message?
- 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
What three things are on the start-line of an HTTP response message?
Protocol version, status code, status text
113
What are HTTP headers?
- case-insensitive name followed by colon : and its value - Communicates to client and server what information to pass
114
Where would you go if you wanted to learn more about a specific HTTP Header?
MDN
115
Is a body required for a valid HTTP request or response message?
No, it will depend on the response
116
What is AJAX?
An asynchronous processing technique used to request and load data from a server without reloading a page
117
What does the AJAX acronym stand for?
Asynchronous JavaScript and XML
118
Which object is built into the browser for making HTTP requests in JavaScript?
new XMLHttpRequest()
119
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
load or onload
120
An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?
Prototype inheritance. An XMLHttpRequest is an object that supports events, therefore, able to have this functionality