JavaScript Flashcards

1
Q

What is the purpose of variables?

A

To give us a location to store data and information to do something with it and use it again in the future.

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

How do you declare a variable?

A

Use the var keyword and then followed by the name of the variable. example:

var totalPets =

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

Using the 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, $ and underscore.

numbers are allowed as long as it is not the first character in the value. So “cat1” works but not “1cat.”

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

Being “case sensitive” means that keywords should be exact.

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

To represent text rather than numbers.

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

What is the purpose of numbers?

A

To count, measure, and calculate.

(example: you would store it as a string because you don’t do ‘math’ with your zip code. A zip code is an identifier. Other examples include address, telephone number, and SSN)

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

To define whether an expression is true or false.

Booleans’ purpose is for computers for making a choice. This gives comp only two choices: “true” or “false.”

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

What does the = operator mean in JS?

A

A symbol used to perform operations on operands (values and 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

State var name, assignment operator and then the 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 is the intentional absence of a value so then you can go back and store a value. It indicates that it does exist but it is not assigned anything.

Undefined means it is also empty but the computer will assign it as it not having any value.

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 a browser console?

A

labels describe what you are inputting. It is mainly for organization.

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

Give 5 examples of JS primitives.

A

JS primitive types are data that is not an object and has no methods or properties.

1) string
2) booleans
3) numbers (also bigint- which are for really big numbers)
4)null
5) 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 data type

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

What type of data type is NaN?

A

NaN = not a number BUT
NaN is a number data type.

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

What is string concatenation?

A

Combines more than one string together. It’s like a secondary functionality for the + operator other than for math.

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

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

A

It can concatenate string and serves as an addition command, adding numbers together.

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

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

A

Takes right operand value and adds it to current value (left operand) and then becomes the new value of the left operand.

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

What are objects used for?

A

Group together a set of properties to store data.

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

What is the reason to group data together to make objects?

A

Objects are a collection of variables to put them in a category indicating that they are similar.

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

What are object properties?

A

Individual pieces of data assigned as a variable that is associated with an object.

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

Describe Object Literal Notation.

A

It starts with a variable and it is defined by an array of key:value pairs separated by colons and then a comma after every key:value pairs except for the last pair of the array.

example:
var student = {
firstName: ‘Sharon’,
lastName: ‘Tieu’
};

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

How do you remove a property from an object?

A

use the Delete operator or use dot notation or bracket notation.

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

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

A

Dot notation or Bracket notation.

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

What are arrays used for?

A

Arrays are typically lists of data especially when we do not know how much data will be in this list.

They are special type of objects that hold a set of related key/value pairs but the key for each value is its index.

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

Describe array literal notation.

A
  • state variable
  • assignment equal operator
    -followed by [ ]
  • inside the [ ], you list the values
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

How are arrays different from “plain” objects?

A

Objects are individually named data stored inside of them whilst an Array is data with an specific order

Objects do not have an order whereas Arrays do have an order.

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

length property - 1

example:
student.length - 1;

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

What is the length property of an array?

A

The total number of values that exists in the array.

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

What is the importance of Data Modeling?

A

Data models are an organization of data.

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

What is a function in Javascript?

A

In Javascript, Functions are are expressions that establishes a relationship between an input and output.

To interact with a function in JS, you can “define” a function or “call” a function.

Example:
function sayHello() {
var greeting = ‘Hello, World!’;
console.log(greeting);
}

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

Describe the parts of a function definition.

A

function sayHello( ) {
var greeting = ‘Hello, World!’;
console.log(greeting);
}

  1. The function keyword - begins the creation of a new function
    a. example: function
  2. An optional name
    a. example: (our function’s name is sayHello.)
  3. A comma-separated list of zero or more parameters, surround by ( ) parentheses
    a. example: (Our sayHello function does not have any parameters.)
  4. The function’s code block, as indicated by an { opening curly brace
  5. An optional return statement
    a. example: (Our sayHello function does not have a return statement.)
  6. The end of the function’s code block
    a. example: as indicated by a } closing curly brace
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

Explain the difference between “Defining” a function and “Calling” a function. How does calling a function work?

A

(Defining a function IS DIFFERENT from calling a function- defining a function does NOT cause the code’s code block to run.)

Once defined, a function becomes another kind of object, however, now it is special in that it can now be CALLED. A function has to be called in order for the code’s code block to run.

Example:
sayHello( ); // will log “Hello, World!” into the console.

var greeting = ‘Hello, World!’;
console.log(greeting);
//can now be executed again and again by name without having to copy-paste the code inside over and over again.

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

Describe the parts in calling a function. (Describe the function call syntax)

A

example(arg1, arg2, arg3);

  1. the function’s name.
    (in this case, our function’s name is called example.)
  2. A comma-separated list of zero or more arguments surrounded by ( ) parenthesis.
    (Our sayHello function does not have any arguments.)

The only way to call a function is parenthesis.

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

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

A

Function definition:
- include function keyword and a code block

Function call:
- will have parenthesis **

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

What is the difference between a parameter and an argument?

A

Parameter - variables that are defined when the function is declared. These are initialized to the values of the arguments supplied. They are local variables to the function that can store values.

Argument - the real values that are actually stored there when the function is called.

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

Why are function parameters useful?

A

Function parameters are useful, because you can pass in certain data to be able to run it again which saves you time from writing several different codes to serve the same function.

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

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

A
  1. The return statement will be replaced by whatever the function called.
  2. A return statement also will stop the function entirely.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

What is a method?

A

A method is a function which is a property of an object. There are two kinds of methods:

1) Instance Methods: built-in tasks performed by an object instance
2) Static Methods: tasks that are called directly on an object constructor.

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

Why do we use log things to the console?

A

To see if our code is working and running. It’s meant for checking values while we are debugging.

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

How is a method different from other functions?

A

Methods are associated with an object, while a function is not.

a method is a form of a function- but they’re just stored in an object.

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

How do you remove the last element from an array?

A

pop( ) method removes (pops) the last element of an array.

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

How do you append an element to an array? (append = add to the end)

A

push( ) method

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

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

A

No.

example: pop( )

The pop( ) method has a return value that is the removed element of an array. It is meant to get rid of something but on the console.log( ) it will show you what you have removed.

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

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

A

there’s a lot :3

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

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

A

MDN

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

6 examples of comparison operators.

A

greater than >
less than <
strictly equal to === (makes sure values are the same if data type and value are equal)
!== strict not equal to
!= is not equal to

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

What data type do comparison expressions evaluate to?

A

Booleans (true or false)

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

Describe the syntax of an if statement.

A

define function with a parameter.

if statement, opening ( with condition ) { opening curly brace, then a return statement ; then semicolon, then } closing curly brace for the if statement.

function introduceWarnerBros(name) {
if (name === ‘yakko’) {
return ‘we are the warner brothers’;
} ;

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

What are the three logical operators?

A

and , or, and not
&& and: both needs to be true to be true
|| or : one condition to be met.
! not:

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

How can two different expressions in the same condition be compared?

A

With Logical Operators

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

What are truthy values? Give an example.

A

A value that is considered true when encountered in a Boolean context.

Example: the string of “space” so ‘ ‘ and an empty object, even empty arrays (because objects and arrays take up space and memory!)

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

What are falsy values?

A

A value that is considered false when encountered in a Boolean context.

Example: NaN

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

What is the purpose of an if statement?

A

It allows the computer to make a decisions based on the criterias that we set.

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

What is the purpose of a loop?

A

To run a set of code(s) over and over again.

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

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

A

They are the “brakes” or checkpoints for your loop

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

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

A

“iteration” is the number of times your code block loop runs on a repetitive basis.

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

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

A

The condition expression of a While loop gets evaluated before each iteration. It is a way to check to see if the code block can even run.

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

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

A

The initialization expression gets evaluated ONCE BEFORE the loop begins.

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

When does the condition expression of a loop take place?

A

Before each iteration takes place.

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

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

A

After each iteration takes place.

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

Besides a return statement, which exits its function block, which keyword exits a loop before its condition expression evaluates to false?

A

Break

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

What does the ++ increment operator do? ( the difference between a++ and ++a ).

A
  1. Substitutes the operator
  2. and increments the variable by one
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
69
Q

How do you iterate through the keys of an object.

A

For - in loop

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

Why do we log things to the console?

A

To make sure everything is loading properly. Helps with debugging and to make sure the code is running.

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

What is a “model”?

A

A model is a representation or recreation of something.

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

Which “document” is being referred to in the phrase Document Object Model?

A

The HTML document.

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

What is the word “object” referring to in the phrase Document Object Model?

A

The word “object” refers to the data type object in javascript.

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

What is a DOM Tree?

A

Document Object Model is a model of the HTML document that is represented as javascript objects.

So The DOM Tree is the representative chunk of a page as javascript objects.

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

Give two examples of document methods that retrieve a single element from the DOM.

A
  1. document.querySelector( )
    ** only use this one^^
  2. document.getElementById( )
76
Q

Give one example of a document method that retrieves multiple elements from the DOM at once.

A
  1. document.querySelectorAll( )
    ** only use this one^^
  2. getElementByClassName( )
  3. getElementsByTagName( )
77
Q

Why might you want to assign the return value of a DOM query to a variable?

A

You can save it in the DOM once so then you don’t have to search for it again.

78
Q

What console method allows you to inspect the properties of a DOM element object?

A

The director method: .dir( )

79
Q

Why would a tag need to be placed at the bottom of the HTML content instead of at the top?

A

The HTML document loads from top to bottom and so when the javascript script elements needs to be at the bottom of the body so then the entire body would have already been loaded.

80
Q

What does document.querySelector() take as its argument and what does it return?

A

It takes a string as an argument and returns the first instance of that element matching that pattern in the document.
It can be a class, type, or so on- querySelector is like a CSS selector.

returns: An Element object representing the first element in the document that matches the specified set of CSS selectors, or null is returned if there are no matches.

81
Q

What does document.querySelectorAll() take as its argument and what does it return?

A

.querySelectorAll( ) selects all the elements that you are put as a string argument. The argument is a string that contains a css selector. It will return a static Node List which is a list of DOM elements. This is an example of an array-like object.

82
Q

Why do we log things to the console?

A

To make sure everything is loading properly. Helps with debugging and to make sure the code is running.

83
Q

What is the purpose of events and event handling?

A

Event handlers are to list of actions that are set up and happens when an action occurs.

This leads to user interactivity to see what users have done.

84
Q

Are all possible parameters required to use a JavaScript method or function?

A

No.

85
Q

What method of element objects lets you set up a function to be called when a specific type of event occurs?

A

.addEventListener( );

86
Q

What is a callback function?

A

A function that is passed into another function as an argument. It is then invoked inside the outer function to complete some kind of routine or action.

87
Q

What object is passed into an event listener callback when the event fires?

A

The event object or the object with all of the data of that event that just occurred.

88
Q

What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?

A

The target property stores the DOM element of where the action originated from.

The importance of event.target is that it can get the element that fired the event, access the properties of the element, and modify some properties of the element, the CSS, and the attributes, etc.

89
Q

What is the difference between these two snippets of code?
1: element.addEventListener(‘click’, handleClick);
2: element.addEventListener(‘click’, handleClick( ) );

A
  1. variable named handleClick that’s being passed as an argument. It is being called when you click. Sets up an event listener, and says when the element is clicked then the handleClick function is invoked.

2: handleClick( ) is a function being invoked from the function (with undefined parameters). The function is called right away instead of letting the browser call it when it happens. This function has no return value, it will be “undefined.” (This will NEVER be the thing that you would want to do btw).
This is passing the return of this function and will return undefined because it doesn’t return anything.

90
Q

What is the className property of element objects?

A

The className property of the Element object sets the value of the class attribute of the specified element.

Allows us to get the value inside of it or set a new element.

91
Q

How do you update the CSS class attribute of an element using JavaScript?

A

select the element first, get class name property and assign a new variable to it.

class.className =

92
Q

What is the textContent property of element objects?

A

You can get what’s currently there or assign a new variable.

93
Q

How do you update the text within an element using JavaScript?

A

Get your element (whether that’s querySelector( ) ) and then use the .textContent method and assign it to a string.

element.textContent = ‘ string of whatever you want to update’

94
Q

Is the event parameter of an event listener callback always useful?

A

No- you don’t always have to use the event listener callback- you use it when you need it.

95
Q

Would this assignment be simpler or more complicated if we didn’t use a variable to keep track of the number of clicks?

A

For the dom-manipulation exercise, it would be more complicated.

96
Q

Why is storing information about a program in variables better than only storing it in the DOM?

A

Variables are easy to change in Javascript but it’s harder to change in HTML.

97
Q

Does the document.createElement( ) method insert a new element into the page?

A

No, it creates a node in the dom

98
Q

How do you add an element as a child to another element?

A

.appendChild( ) method

99
Q

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

A

We pass two strings: the name of the attribute and the value being applied to that attribute.

100
Q

What steps do you need to take in order to insert a new element into the page?

A

create the element with document.createElement( ) and assign it a variable.
Create a class name for it with .setAttribute( ) and then append it as a child to its parent.

101
Q

What is the textContent property of an element object for?

A

attaches text

102
Q

Name two ways to set the class attribute of a DOM element.

A
  1. .setAttribute ( ) method
  2. there is a property named className that you can use to set the name of the attribute.
103
Q

What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?

A
  1. makes it reusable
  2. makes it efficient and saves time so we don’t have to write the same function over and over again.
104
Q

What is the event.target?

A

The element that triggered an event. In other words, where the event originated from.

105
Q

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

A

It is removed from the document flow entirely. It’s technically still there and it still exists, but to the user, they cannot see it.

106
Q

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

A

It takes a css selector as a string and returns a Boolean value if it matches the corresponding element.

107
Q

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

A

The getAttribute() method of the Element interface returns the value of a specified attribute on the element.

108
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

You would have to add individual eventListeners for each individual element.

109
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

We would have to write a condition for each possible view.

110
Q

What is JSON?

A

JavaScript Object Notation (JSON) is a standard text-based format for representing structured data based on JavaScript object syntax. It is commonly used for transmitting data in web applications (e.g., sending some data from the server to the client, so it can be displayed on a web page, or vice versa).

Specifically, JSON is a string whose format resembles JavaScript object literal format. You can include the same basic data types inside JSON as you can in a standard JavaScript object - strings, numbers, arrays, booleans, and other object literals.

111
Q

What are serialization and deserialization?

A

Serialization: the process of turning an object in memory into a stream of bytes so you can do stuff like store it on a disk or send it over the network.
(converting an Object into a stream of bytes so it can be transferred over a network or a consistent storage.)

Deserialization: the reverse process of serialization: turning a stream of bytes into an object in memory.

112
Q

Why are serialization and deserialization useful?

A

serialization: to easily transmit data to somewhere else.

deserialization: trying to get a piece of data out of a larger string.

113
Q

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

A

JSON.stringify( )

argument: an array or object
return: a JSON string

114
Q

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

A

JSON.parse( )

argument: a JSON string
return: an array or object

115
Q

How do you store data in localStorage?

A

using the setItem( ) method of the localstorage object.

the arguments of setItem( ) are:
1. keyName: a string containing the name of the key that you want to create/update
2. keyValue: a string containing the value you want to give the key you are creating/updating

116
Q

How do you retrieve data from localStorage?

A

using the getItem( ) method.

the argument of getItem( ) is:
1. keyName: a string containing the name of the key you want to retrieve the value of.

117
Q

What data type can localStorage save in the browser?

A

localStorage stores Strings.

118
Q

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

A

Just before the document loads such as refreshing your document, closing your tab, or closing your browser.

119
Q

What is the purpose for localStorage.

A

To store values to be used for later for the user.

120
Q

What is the event.target?

A

Helps you find the element of where the target originated from.

121
Q

Why is it possible to listen for events on one element that actually happen its descendent elements?

A

Event bubbling

122
Q

What DOM element property tells you what type of element it is?

A

The DOM element property that tells you the type of element is called tagName or nodeName.

tagName represents element names while
nodeName refers to white space nodes or text nodes

123
Q

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

A

element.closest( ) takes the closest parent selector and can go up the ancestral chain. It’s like a reversed querySelector( ), because element.closest( ) returns the parent selector.

It will return null if it cannot detect what you are selecting.

124
Q

How can you remove an element from the DOM?

A

.remove() element

125
Q

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?

A

add the .addEventListener( ) method to the parent element.

126
Q

What is a method?

A

A function that is stored into a property of an object.
There are two different kinds of methods: Static Method and Instance Method.

127
Q

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

A

method Definition defines function definition and assigns it to a property.
A method Call is an object.methodname.( )

128
Q

Describe method definition syntax (structure).

A

property: anonymousFunction (parameters) {
variable then an assignment operator (=) followed by the result of that method;
return variable;
};

example:
add: function (x , y) {
var sum = x + y;
return sum;
};

129
Q

Describe method call syntax (structure).

A

use dot notation of the object to access it and then parenthesis to call the function:

nameOfObject.nameOfMethod ( arguments );

130
Q

How is a method different from any other function?

A

It is stored inside an object.

131
Q

** What is the defining characteristic of Object-Oriented Programming?

A

OOP is to create objects that can carry data and behavior as methods within a shared space.

132
Q

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

A
  1. Abstraction
  2. Encapsulation
  3. Inheritance
  4. Inheritance
133
Q

What is “abstraction”?

A

A simpler way to access complex behavior. It is a means to simplify w/o having to fully understand the complexity of it. You can do something without understanding all of the complex stuff needed to perform a certain behavior.

134
Q

What does API stand for?

A

Application Programming Interface.

135
Q

What is the purpose of an API?

A

A set of tools that allow you to access complex functionalities.
Ex: the DOM.

136
Q

What is this in JavaScript?

A

In JS, the keyword “this” refers to an object. Which object depends on how this is being invoked (used or called). The this keyword refers to different objects depending on how it is used: in an object method, this refers to the object.

137
Q

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

A

“Implicit parameter” means it is a parameter being invoked in a function that is not being directly stated or listed in the function but it is being used.

parameter = a var that we create in a function definition that serves as a placeholder until it is called

implicit = “implied” which means it is present even though it is not directly state.

138
Q

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

A

Call time.

139
Q

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);
}
};

A

the value of this is: nothing. this is no value.
because! you are not calling it during call time.

140
Q

What does this refer to in the following code snippet?

character.greet( );

A

result is: It’s-a-me, mario!

this: character (becaue character is to the left of the “dot” in character.greet( );

141
Q

var character = {
firstName: ‘Mario’,
greet: function ( ) {
var message = ‘It's-a-me, ‘ + this.firstName + ‘!’;
console.log(message);
}
};

Given the above character object, what is the result of the following code snippet? Why?

A

this:
there is nothing left of the dog.

142
Q

character.greet();

Given the above character object, what is the result of the following code snippet? Why?

A

It’s-a-me, Mario!

143
Q

var hello = character.greet;
hello();

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

A

Look at the left of the dot (which is the calling object), it will let you know what THIS is referring to.

144
Q

var hello = character.greet;
hello();

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

A

Look at the object to the left of the dot. So in this case, it is character.

145
Q

What kind of inheritance does the JavaScript programming language use?

A

Prototypal inheritance. This means an object “inherits” properties from another object via the prototype linkage.

146
Q

What is a prototype in JavaScript?

A

A prototype is an object or behavior that has access / inheritance of another object via prototype linkage.

147
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

Through Prototypal Inheritance.

148
Q

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

A

It will look for it in the prototype.

149
Q

What does the new operator do?

A

The new operator lets you create an instance of a user-defined object type or of one of the built-in object types that has a constructor function.

150
Q

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

A

The prototype property. This will hold an object and this object will store shared behavior that is created with new.

151
Q

What does the instanceof operator do?

A

The instanceof operator tests the presence of constructor.prototype in object’s prototype chain. The value of instanceof test can change depending on the changes to the prototype property of constructors. It can also be changed by changing an object’s prototype using Object.setPrototypeOf( ) ;

left side is the variable or whatever you want to check and the right will be a function definition.

152
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

153
Q

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

A

setInterval( ); function

154
Q

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

A

0 milliseconds

155
Q

What do setTimeout( ) and setInterval( ) return?

A

The returned intervalID is a numeric, non-zero value which identifies the timer created by the call to setInterval() ; this value can be passed to clearInterval() to cancel the interval.

setInterval() returns a numeric, non-zero value which identifies the timer created by the call to setInterval(); this value can be passed to clearInterval() to cancel the interval.

156
Q

(http-messages) What is a client?

A

Clients are server requesters. So someone who wants a certain service.

157
Q

What is a server?

A

Servers are a piece of computer hardware or software (computer programs) that provides functionality for other programs or devices called “clients.” Servers share data and resources amongst clients or to perform certain computations.

158
Q

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

A

The browser issues a GET or POST request method to a web server when we visit a URL.

159
Q

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

A

The 3 things on the start-line HTTP request message are:
1. description of the request to be implemented
2. status of whether it is successful or a failure
3. the start-line will always be a single line.

160
Q

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

A

The 3 things on the start-line HTTP Response message are:
1. The protocol version (usually HTTP/1.1).
2. The status code: to indicate success or failure of the request. (Common status codes are 200, 404, or 302).
3. A status Text: a brief, purely informational, textual description of the status code to help humans understand the HTTP message.

A typical status line looks like:
HTTP/1.1 404 NOT FOUND

161
Q

What are HTTP headers?

A

HTTP headers allow the client and server to pass information with an HTTP request or response.
HTTP headers consists of its case-insensitive name followed by a colon ( : ), then by its value.

In other words, this is meta-data that provides additional information. This is the equivalent of the element in an HTML document :3

In other words, a HTTP Header is a field of an HTTP response or requests that passes additional context and metadata about the response or requests.

162
Q

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

A

MDN

163
Q

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

A

No. A body is optional for a valid HTTP request or response message.

example: 201

164
Q

What is AJAX?

A

A programming practice of building complex, dynamic webpages using XMLHttpRequest. This is what makes a webpage dynamic

165
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript and XML.

166
Q

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

A

new XMLHttpRequest( );

167
Q

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

A

‘load’

168
Q

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

A

Because of prototypal inheritance.

169
Q

Explain the syntax of event.target.

A

The target property can only be obtained if the event of an element is being listened to.

element.addEventListener(“input”, function(event) {
//event.target is now accessible
console.log(event.target)
})

170
Q

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

A

Math.floor( )

171
Q

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

A

focus event

172
Q

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

A

blur event

173
Q

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

A

input event

174
Q

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

A

submit event

175
Q

What does the event.preventDefault() method do?

A

The preventDefault() method cancels the event if it is cancelable, meaning that the default action that belongs to the event will not occur. For example, this can be useful when: Clicking on a “Submit” button, prevent it from submitting a form. Clicking on a link, prevent the link from following the URL.

In other words, it prevents the default behavior of the method.
it should always be the first in a form function.

176
Q

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

A

elements property

177
Q

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

A

value property

178
Q

What is one risk of writing a lot of code without checking to see if it works so far?

A

it will be difficult to debug and to pinpoint where your mistake is and to fix it. Limit the stuff you need to fix by continuously checking on your progress.

179
Q

What is an advantage of having your console open when writing a JavaScript program?

A

You can debug right away when something doesn’t work

180
Q

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

A

it will refresh the page and submit the data to the URL

181
Q

what is an api?

A

Application Programming Interface.
API is the messenger that takes requests and tells the server system what the client wants to do and returns a response back.

182
Q
A
183
Q
A
184
Q
A
185
Q
A
186
Q
A