Javascript Flashcards

(161 cards)

1
Q

What is the purpose of a number?

A

To assign numerical value

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

What is the purpose of a boolean?

A

To determine if something is true or false

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

What does the = operator mean in JavaScript?

A

It says that you are going to assign a value to a variable

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

How do you update the value of a variable?

A

By recalling the variable by the name and using the assignment operator to assign it a new value

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

What is the difference between null and undefined?

A

null is an assigned value. It means nothing.(intentional empty) undefined means a variable has been declared but not defined yet

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

Why is it a good habit to include “labels” when you log values to the browser console?

A

to help you debug, but if you do not include “labels”, it can be very confusing instead of helpful

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

Give five examples of JavaScript primitives.

A

string, number, boolean, undefined, and null.

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

What is string concatenation?

A

Taking two strains and putting them together

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

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

A

To add values and concatenate

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

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

A

adds the value on the right, to the variable on the left, and then assigns that value back into the variable on the left

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

What are arrays used for?

A

To store a list of values

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

Describe array literal notation.

A

The values are assigned to the array inside a pair of square brackets, and each value is separated by a comma.

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

How are arrays different from “plain” objects?

A

It holds a list of related values in order, white object holds list of values out of order

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

What is the length property of an array?

A

It holds the number of items in the array

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

How do you calculate the last index of an array?

A

Subtracting 1 from the length of an array

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 together a set of variables and functions to create a model

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

What are object properties?

A

Variables that are part of an object.

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

Describe object literal notation.

A

Object is contained by curly braces,

You separate each key from its value by using a colon, separate each property and method with a comma.

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

Use keyword delete operator followed by dot notation

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

Using dot notation or brackets notation

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

What is a function in JavaScript?

A

Functions allow you to package up code for use later in your program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Describe the parts of a function definition:
Function keyword to bring a new function An optional name A comma-separated list of zero or more parameters The start of the code block enclosed by curly braces An optional return statement
26
Describe the parts of a function call.
The function’s name and a comma-separated list of zero or more arguments surrounded by ()
27
When comparing them side-by-side, what are the differences between a function call and a function definition?
Call, recalls the function and executes the code to run, definition defines and states what the code is going to do
28
What is the difference between a parameter and an argument?
Parameters are used to define a function, arguments are used to call a function.
29
Why are function parameters useful?
Because they allow to function to be more flexible
30
What two effects does a return statement have on the behavior of a function?
Causes the function to produce a value we use in our program | Prevents any more code in the code block from being run
31
Why do we log things to the console?
To use as a debugging tool and learning to play and learn about JS
32
What is a method?
A method is a function which is a property of an object
33
How is a method different from any other function?
A method is associated with an object while a function is not
34
How do you remove the last element from an array?
pop()
35
How do you round a number down to the nearest integer?
floor()
36
How do you generate a random number?
Math.random()
37
How do you delete an element from an array?
splice()
38
How do you append an element to an array?
push() unshift()
39
How do you break a string up into an array?
split()
40
Do string methods change the original string? How would you check if you weren't sure?
No they don’t change original string, assigning original string to a var and checking with new string
41
Roughly how many string methods are there according to the MDN Web docs?
60+ methods
42
Is the return value of a function or method useful in every situation?
no
43
Roughly how many array methods are there according to the MDN Web docs?
30+ methods
44
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
mdn
45
Give 6 examples of comparison operators.
> , < , >= , <= , === , and !==
46
What data type do comparison expressions evaluate to?
Boolean
47
What is the purpose of an if statement?
guides a program to make decisions based on specified criteria
48
Is else required in order to use an if statement?
no
49
Describe the syntax (structure) of an if statement.
If ( exp ) { Code block to run }
50
What are the three logical operators?
And or not
51
How do you compare two different expressions in the same condition?
With and / or logical operators
52
What is the purpose of a loop?
To perform repeated tasks based on a condition
53
What is the purpose of a condition expression in a loop?
Tells the loop when to stop
54
What does "iteration" mean in the context of loops?
Repetition of a function or process
55
When does the condition expression of a while loop get evaluated?
before executing the statement. And one after
56
When does the initialization expression of a for loop get evaluated?
Before each loop iteration, just once
57
When does the condition expression of a for loop get evaluated?
Each time before the loop runs
58
When does the final expression of a for loop get evaluated?
At the end of each loop iteration.
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?
Increase the number by 1 and reassigns the value back into variable
61
How do you iterate through the keys of an object?
Using a for in loop
62
Why do we log things to the console?
To debug and make sure things are working.
63
What is a "model"?
The representation of something
64
Which "document" is being referred to in the phrase Document Object Model?
The document which is being represented on the web page
65
What is the word "object" referring to in the phrase Document Object Model?
Its referring to each different part of the page being loaded in the window
66
What is a DOM Tree?
It is the model of a web page
67
Give two examples of document methods that retrieve a single element from the DOM.
getElementByID & querySelector
68
Give one example of a document method that retrieves multiple elements from the DOM at once.
getElementsbyClassName
69
Why might you want to assign the return value of a DOM query to a variable?
It helps page speed, by saving the reference location of the value in the Dom tree.
70
What console method allows you to inspect the properties of a DOM element object?
console.dir
71
Why would a tag need to be placed at the bottom of the HTML content instead of at the top?
To help the page load faster by loading the html elements first.
72
What does document.querySelector() take as its argument and what does it return?
Css selector syntax and returns only the first of the matching elements
73
What does document.querySelectorAll() take as its argument and what does it return?
Css selector syntax and returns all of those that match
74
What event is fired when a user places their cursor in a form control?
Focus event
75
What event is fired when a user's cursor leaves a form control?
Blur event
76
What event is fired as a user changes the value of a form control?
Form event
77
What event is fired when a user clicks the "submit" button within a ?
Submit event
78
What does the event.preventDefault() method do?
Cancel default behavior of event
79
What does submitting a form without event.preventDefault() do?
Reload the page with its return values in the address bar
80
What property of a form control object gets and sets its value?
Value attribute
81
What is one risk of writing a lot of code without checking to see if it works so far?
Bugs and issues / broken code
82
What is an advantage of having your console open when writing a JavaScript program?
You are able to check if any code is broken or if anything is not showing correct output
83
Are all possible parameters required to use a JavaScript method or function?
no
84
What method of element objects lets you set up a function to be called when a specific type of event occurs?
AddEventListerner Function
85
What is a callback function?
Is any function that is passed to another function but is not called.
86
What object is passed into an event listener callback when the event fires?
Event object
87
What is the event.target? If you weren't sure, how would you check? Where could you get more information about it?
Is the element which dispatches the element. MDN
88
What is the className property of element objects?
Gets and sets the value of the class attribute of the specified element
89
How do you update the CSS class attribute of an element using JavaScript?
element.className = “class”;
90
What is the textContent property of element objects?
Property that stores the text content of the element
91
How do you update the text within an element using JavaScript?
.textcontent =
92
Is the event parameter of an event listener callback always useful?
No
93
Would this assignment be simpler or more complicated if we didn't use a variable to keep track of the number of clicks?
More complicated, we would have to access the Dom as the source of truth.
94
Why is storing information about a program in variables better than only storing it in the DOM?
Because we can refer back it later and reuse as many times as we need.
95
Does the document.createElement() method insert a new element into the page?
no
96
* How do you add an element as a child to another element?


appendChild()
97
* What do you pass as the arguments to the element.setAttribute() method?

name to attribute, value
98
What steps do you need to take in order to insert a new element into the page?
appendChild that new element to its parent
99
* What is the textContent property of an element object for?

the text content and all its decendaces
100
* Name two ways to set the class attribute of a DOM element.
.
className, setAttribute()
101
What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?
that it is repeatable to work with data structures, the availability to separate function so it doesn’t affect anything else in the program , incase we need to change data at a later point
102
What is the event.target?
The target event property returns the element that triggered the event
103
Why is it possible to listen for events on one element that actually happen its descendent elements?
Because of event flow
104
What DOM element property tells you what type of element it is
nodeName / Tagname
105
What does the element.closest() method take as its argument and what does it return? How can you remove an element from the DOM?
returns the first ancestor of the selected element Takes a selector as the argument With element.remove() function
106
If you wanted to insert new clickable DOM elements into the page using JavaScript, how could you avoid adding an event listener to every new element individually?
By adding an event listener to its parent element
107
What is the event.target?
Target of the event being interacted with
108
What is the affect of setting an element to display: none?
It hides all the content within that element
109
What does the element.matches() method take as an argument and what does it return?
A selector as its argument and returns true or false value
110
How can you retrieve the value of an element's attribute?
getAttribute() method
111
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?
add individual addeventlisteners for each elemnt
112
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?
Using an if statement if one tab is ‘showing’ hide all other tabs
113
What is JSON?
JSON is a lightweight format for storing and transporting data.
114
What are serialization and deserialization?
Serialization is a mechanism of converting the state of an object into a byte stream Deserialization is the reverse process where the byte stream is used to recreate the actual Java object in memory.
115
Why are serialization and deserialization useful?
They help to sa¥ve file¥¥s onto the local disk or sent over the network to any other machine
116
How do you serialize a data structure into a JSON string using JavaScript?
stringify() 
117
How do you deserialize a JSON string into a data structure using JavaScript?
JSON.parse( string, function )
118
How do you store data in localStorage?
localStorage.setItem() KEY, VALUE
119
How do you retrieve data from localStorage?
localStorage.getItem()
120
What data type can localStorage save in the browser?
JSON Data
121
When does the 'beforeunload' event fire on the window object?
is fired when the window, the document and its resources are about to be unloaded.
122
What is a method?
Is a function which is a property of an object
123
Describe method definition syntax (structure).
Object {method: function() {} }
124
Describe method call syntax (structure).
Object.method()
125
How is a method different from any other function?
Difference is that a method is associated with an object while a function is not
126
What is the defining characteristic of Object-Oriented Programming?
objects can contain both data (as properties) and behavior (as methods).
127
What are the four "principles" of Object-Oriented Programming?
Abstraction, encapsulation, inheritance, polymorphism
128
What is "abstraction"?
being able to work with (possibly) complex things in simple ways. 
129
What does API stand for?
Application programming interface
130
What is the purpose of an API?
its purpose is to facilitate a way for two or more computer programs to communicate with each other.
131
What is this in JavaScript?
the this keyword refers to an object. Which object depends on how this is being invoked (used or called).
132
What does it mean to say that this is an "implicit parameter"?
meaning that it is available in a function's code block even though it was never included in the function's parameter list or declared with var
133
When is the value of this determined in a function; call time or definition time?
Call time
134
``` What does this refer to in the following code snippet? var character = { firstName: 'Mario', greet: function () { var message = 'It\'s-a-me, ' + this.firstName + '!'; console.log(message); } }; ```
Object character
135
Given the above character object, what is the result of the following code snippet? Why?
It returns the greet function inside character object, because this is being referred to character object
136
Given the above character object, what is the result of the following code snippet? Why?
It returns It's-a-me, undefined!, because the function if not being called.
137
How can you tell what the value of this will be for a particular function or method definition?
By seeing what object the this method is inside of
138
How can you tell what the value of this is for a particular function or method call?
By looking at what is left of the period
139
What kind of inheritance does the JavaScript programming language use?
Prototype based inheritance
140
What is a prototype in JavaScript?
The prototype is an object that is associated with every functions and objects by default in JavaScript
141
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?
Because of prototypes property’s they inherit.
142
If an object does not have it's own property or method by a given key, where does JavaScript look for it?
In its prototype chain
143
What does the new operator do?
The new operator lets developers create an instance of a user-defined object type or of one of the built-in object types that has a constructor function
144
What does the instanceof operator do?
is used to check the type of an object at the run time. It returns a boolean value(true or false).
145
What is a "callback" function?
A callback function is a function passed into another function as an argument,
146
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?
By using the setTimeout function
147
How can you set up a function to be called repeatedly without using a loop?
Using the setinterval function
148
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0
149
What do setTimeout() and setInterval() return?
A unique intervalID
150
What is a client?
a client is any computer hardware or software device that requests access to a service provided by a server
151
What is a server?
A server is a computer program or device that provides a service to another computer program and its user, also known as the client.
152
Which HTTP method does a browser issue to a web server when you visit a URL?
GET
153
What three things are on the start-line of an HTTP request message?
An HTTP method, a verb (like GET , PUT or POST ) The request target, usually a URL, HTTP version
154
What three things are on the start-line of an HTTP response message?
The protocol version, usually HTTP/1.1 . A status code, indicating success or failure of the request. Common status codes are 200 , 404 , or 302. A status text.
155
What are HTTP headers?
HTTP headers let the client and the server pass additional information with an HTTP request or response.
156
Is a body required for a valid HTTP request or response message?
no, requests fetching resources, like GET, HEAD, DELETE, or OPTIONS, usually don't need one. 
157
What is AJAX?
Is a technique for loading data into part of a page without having to refresh the entire page.
158
What does the AJAX acronym stand for?
Asynchronous Javascript and XML
159
Which object is built into the browser for making HTTP requests in JavaScript?
XMLHttpRequest
160
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
Load event
161
Bonus Question: An XMLHttpRequest object has an | addEventListener() method just like DOM elements. How is it possible that they both share this functionality?
They both share a prototype object, prototype inheritance