JavaScript Flashcards

1
Q

What is the purpose of variables?

A

To store pieces of data

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

How do you declare a variable?

A

With the var keyword (let,const)

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

Initialize a variable by assigning it to a value with an equal sign

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

Dollar signs, underscores and letters

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

Variable names can be the same word but with different casings. Ex) var pRicE; and var Price; both work

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

For storing and manipulating 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

Data type to represent and manipulate number 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

a True or false value for all javascript comparison and conditions

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 between the variable and data

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

Assign the variable to a new value; no declaration

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

What is the difference betweennullandundefined?

A
  • Undefined is not assigned

- Null is an error,

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 confirm what type of data type you are working with, or what value is inside the variable

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

Depends. Going from left to right of the expression. It’ll work out the math operations then concatenate if a string is there.

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

What is string concatenation?

A

Adding two operands together with an addition operator

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

A boolean value

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

Adds the value on the right of the variable to the left of the operator. Then assigns the result to the variable

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

What are objects used for?

A

Allow a collection of data for a specific theme. Data organization

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

What are object properties?

A

Variable within an object literal

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

Describe object literal notation

A

Key value pairs within curly braces being assigned to a variable name

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

Using the “delete” operator

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

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

A

Using dot notation or you can use bracket notation

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

What are arrays used for?

A

To list out multiple values of similar data

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

Describe array literal notation

A

Square brackets with data divided by commas being assigned to a variable declaration

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
How are arrays different from "plain" objects
Key numbered index, 0 based
26
What number represents the first index of an array
0
27
What is the length property of an array?
Numbers of entries in an array
28
How do you calculate the last index of an array?
Array[Array.length - 1]
29
What is a function in JavaScript
Set of reusable code saved under a special type of object to be invoked(called);
30
Describe parts of a function definition
Curly braces around a code block being assigned to a function definition with parentheses 1. function 2. name(optional) 3. parameters(optional) 4. codeblock 5. return
31
Describe the parts of a function call
Invoke the name of the function with arguments within the parentheses
32
When comparing them side-by-side, what are the differences between a function call and a function definition.
Seeing a code block means its a function definition. Then also telling what is an argument and a parameter.
33
What is the difference between a parameter and an argument?
A parameter is before calling the function
34
Why are function parameters useful?
Pass additional information into the function, couldn't have dynamic data without it
35
What two effects does a return statement have on the behavior of a function?
Produce a value where the function is called, instead of having undefined.
36
Can code execute after the return keyword?
No. It finishes after return is ran.
37
Why do we log things to the console?
To keep track of any updates to variables
38
What is a method
A function property within an object
39
How is a method different from any other function?
Method is a function of an object.
40
How do you remove the last element from an array?
.pop()
41
How do you round a number down to the nearest integer?
Math.floor()
42
How do you generate a random number?
Math.random
43
How do you delete an element from an array?
.splice, .pop, or shift() all alter the array
44
How do you append an element to an array?
.push or .unshift()
45
How do you break a string up into an array?
.split(" "). Space would divide words
46
Do string methods change the original string? How would you check if you weren't sure?
No, because primary data types are immutable. Console.log
47
Roughly how many string methods are there according to the MDN Web docs?
30
48
Is the return value of a function or method useful in every situation?
No, because methods like splice();
49
Roughly how many array methods are there according to the MDN Web docs?
36
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.
greater than, less than, greater than or equal to, less than or equal to, strict equality, not comparison
52
What data type do comparison expressions evaluate to?
Booleans
53
What is the purpose of an if statement?
Executes a statement if a specific condition is true, another statement can be executed if false
54
Is else required in order to use an if statement?
No
55
Describe the syntax (structure) of an if statement.
if keyword, condition expression, brace for code block, statement1
56
What are the three logical operators?
And, or, not, || = double pipe ! = bang
57
How do you compare two different expressions in the same condition?
Using a logical operator between conditional
58
What is the purpose of loops?
To perform repeated tasks based on how many times the condition remains true.
59
What is the purpose of a condition expression in a loop?
Tells the loop when to run as long as the result remains true
60
What does "iteration" mean in the context of loops?
Every instance the code between the code block runs
61
When does the condition expression of a while loop get evaluated?
When does the condition expression of a while loop get evaluated?
62
When does the initialization expression of a for loop get evaluated?
Executed ONCE at the very start of the loop.
63
When does the condition expression of a for loop get evaluated?
Right before each iteration.
64
When does the final expression of a for loop get evaluated?
Happens at the end of each loop. Usually to increment or decrement a counter.
65
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
Break. | -Rare usage. But can be used to exit a loop when found a value.
66
What does the ++ increment operator do?
Adds one to the operand. Depending on the position of it.
67
How do you iterate through the keys of an object?
Using for...in to iterate over properties of an object.
68
What event is fired when a user places their cursor in a form control?
'focus'
69
What event is fired when a user's cursor leaves a form control?
'blur'
70
What event is fired as a user changes the value of a form control?
'input'
71
What event is fired when a user clicks the "submit" button within a ?
'submit'
72
What does the event.preventDefault() method do?
'Prevents the page from automatically reloading the page' | Without it, if the form is wrong (even if method and get link to same page), page keeps reloading.
73
Where should event.preventDefault() go?
At the beginning of the function.
74
What does submitting a form without event.preventDefault() do?
Reloads the page
75
What property of a form element object contains all of the form's controls.
.elements
76
What property of form a control object gets and sets its value?
value
77
What is JSON?
text-based data string format. Replicating javascript object syntax
78
What are serialization and deserialization?
- Serialization: Converting unordered data like an object to storable bits, which is usually a string - Deserialization is the reverse. Turning that string of text into an object in memory.
79
Why are serialization and deserialization useful?
- Allows saving the state of an object and recreating it as needed. - Allows transferring data efficiently
80
How do you serialize a data structure into a JSON string using JavaScript?
Var something = JSON.stringify([{}]
81
How do you deserialize a JSON string into a data structure using JavaScript?
``` var obj = JSON.parse('[{"id:":"31023"}]'); -Notice the double quotes. ```
82
What is the affect of setting an element to display: none?
That affected element disappears on the web page, and it won't interfere with the document flow
83
What does the element.matches() method take as an argument and what does it return?
Returns a boolean value indicated if the element is matched with the specific CSS selector
84
How can you retrieve the value of an element's attribute?
getAttribute method of the element
85
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?
Make a new event listener for every element
86
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?
Massive conditional block for every
87
How to you store data in localStorage?
- With storage.setItem(key,value); | - .setItem method,
88
How to you retrieve data from localStorage?
getItem();
89
What data type can localStorage save in the browser?
string data
90
When does the 'beforeunload' event fire on the window object?
When the window,document and its resources are about to be unloaded
91
What is a method?
Methods are functions that are stored in object properties.
92
How can you tell the difference between a method definition and a method call?
- Method definition goes within the object with the code block - Method call is outside the object and is called as a property(method) on the object. - Has the dot.
93
Describe method definition syntax (structure).
- Create a new property inside our object - Property Name : function(){ code block} - You can assign the property with the value function outside the object as well.
94
Describe method call syntax (structure).
Property method of the object being calling with arguments;
95
How is a method different from any other function?
Unlike other functions, methods only exist within this object, so you must call it along the object.
96
What is the defining characteristic of Object-Oriented Programming?
Working with objects, which contain both data(as properties) and behavior(as methods)
97
What are the four "principles" of Object-Oriented Programming?
Abstraction, Encapsulation, Inheritance, Polymorphism
98
What is "abstraction"?
Being able to work complex things in simple ways
99
What does API stand for?
Application Programming Interface
100
What is the purpose of an API?
- Give programmers a way to interact with a system in a simplified, consistent fashion. - Specifically abstraction
101
Procedural programming
Loosely means declared variables to hold the state of application and defined functions to update those variables. - Variables and functions were separate
102
What is a "callback" function?
- Function being passed around as a value. | - which is then invoked inside the outer function to complete some kind of routine or action.
103
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 & setInterval
104
How can you set up a function to be called repeatedly without using a loop?
setInterval(function, seconds);
105
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0ms. The value of omitting it, it runs after the functions without setInterval and setTimeout.
106
What do setTimeout() and setInterval() return?
- It returns an interval ID which uniquely identifies the interval, so you can remove it later by calling clearInterval() - 1000 = id of 1. - Interval and Timeout share incrementing IDs
107
What is this in JavaScript?
An implicit parameter of all JS functions. | This, refers to the object it belongs to. Alone, this refers to the global object.
108
What does it mean to say that this is an "implicit parameter"?
Available in a functions code block even though it was never included in the functions parameters list or declared with var.
109
When is the value of this determined in a function; call time or definition time?
When the function is called.
110
How can you tell what the value of this is for a particular function or method call?
this is only a value when function is being invoked. this is the object to the left of the dom.
111
What is the goal of Inheritance?
To move properties and methods we'd like to reuse into a prototype object and tell other objects to simply delegate to that prototype object.
112
Why is it possible to call doggo.speak() or kitteh.speak() even though they don't have those methods defined on them?
These methods are located in the prototype object
113
What kind of inheritance does the JavaScript programming language use?
Prototypal Inheritance
114
What is a prototype in JavaScript?
Object with set properties, and we can add our own methods on it
115
How do we set the prototype of a specified object to another object?
Object.setPrototypeOf(obj, prototype)
116
How do we get the prototype of a specified object?
Object.getProtypeOf(obj);
117
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?
Every object has a set property list of methods
118
If an object does not have it's own property or method by a given key, where does JavaScript look for it?
In the object [[prototype]] property
119
What does the new operator do?
4 Step: 1. Create a blank JavaScript Object 2. Adds a property to the new Object (__proto__) that links to the constructor function's prototype object 3. Binds the newly creating object instance as the `this` context 4. Returns `this` if the function doesn't return an object
120
What property of JavaScript functions can store shared behavior for instances created with new?
.Prototype property
121
What does the instanceof operator do?
Tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object - Returns a boolean value.
122
Is there a return from the new instance property
Yes, and you don't have to specifically return it.
123
What is AJAX?
AJAX is a technique for creating fast and dynamic web pages.
124
What does the AJAX acronym stand for?
Asynchronous JavaScript and XML.
125
Which object is built into the browser for making HTTP requests in JavaScript?
XMLHttpRequest()
126
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
'load'
127
An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?
- XML object and DOM elements are instaces of Object | - Share object in their prototypal chain