JavaScript Flashcards

1
Q

JAVASCRIPT-PRIMITIVES-AND-VARIABLES

What is the purpose of variables?

A

Variables are used to store data for the computers to use in the future

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

JAVASCRIPT-PRIMITIVES-AND-VARIABLES

How do you declare a variable?

A

use a keyword (var, let, const) and variable name and =

Example: var example = 100;

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

JAVASCRIPT-PRIMITIVES-AND-VARIABLES

How do you initialize (assign a value to) a variable?

A

use an equal sign

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

JAVASCRIPT-PRIMITIVES-AND-VARIABLES

What characters are allowed in variable names?

A

letter, numbers, $, underscore,

numbers cant be first

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

JAVASCRIPT-PRIMITIVES-AND-VARIABLES

What does it mean to say that variable names are “case sensitive”?

A

Car= and car= are different variables

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

JAVASCRIPT-PRIMITIVES-AND-VARIABLES

What is the purpose of a string?

A

for storing text that wouldn’t make sense to JavaScript

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

JAVASCRIPT-PRIMITIVES-AND-VARIABLES

What is the purpose of a number?

A

For doing calculations;

If the number is a zipcode then store as string;

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

JAVASCRIPT-PRIMITIVES-AND-VARIABLES

What is the purpose of a boolean?

A

it is for letting computers make a decision that is true or false

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

JAVASCRIPT-PRIMITIVES-AND-VARIABLES

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

JAVASCRIPT-PRIMITIVES-AND-VARIABLES

How do you update the value of a variable?

A

Update the value of a variable by assigning a new value to the variable name without the keyword

Example:
let a = 2; for declaring a variable
a = 5; for updating a variable (no need for keyword)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

JAVASCRIPT-PRIMITIVES-AND-VARIABLES

What is the difference between null and undefined?

A
  • null is absents of value intentionally
    (ex: optional user input)
  • undefined is not trustworthy
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

JAVASCRIPT-PRIMITIVES-AND-VARIABLES

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

A

Label within the console.log to know where you’re getting values from / for organization purposes

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

JAVASCRIPT-PRIMITIVES-AND-VARIABLES

Give five examples of JavaScript primitives.

A

string, number, boolean, null, and undefined

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

JAVASCRIPT-OPERATORS-AND-EXPRESSIONS

What data type is returned by an arithmetic operation?

A

numeric data

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

JAVASCRIPT-OPERATORS-AND-EXPRESSIONS

What is string concatenation?

A

Process of joining together two or more strings to create one new string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
JAVASCRIPT-OPERATORS-AND-EXPRESSIONS
What purpose(s) does the + plus operator serve in JavaScript?
A

adds one value to another;

addition of numbers and concatenation of strings

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

JAVASCRIPT-OPERATORS-AND-EXPRESSIONS
What data type is returned by comparing two values
(, ===, etc)?

A

booleans (true or false)

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

JAVASCRIPT-OPERATORS-AND-EXPRESSIONS

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

A

left operand = left operand + right operand

Example: 2 += 3 = 5

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

JAVASCRIPT-OBJECTS

What are objects used for?

A

objects {} are used group together a set of variables and functions to create a model / representation of something

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

JAVASCRIPT-OBJECTS

What are object properties?

A

properties tell us about the object;
the variable of an object;

Example: name, age, etc.

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

JAVASCRIPT-OBJECTS

Describe object literal notation.

A

Store object in variable, within opening and closing curly braces are properties and their values;

Example: 
var object = { properties: value }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

JAVASCRIPT-OBJECTS

How do you remove a property from an object?

A

Use delete
Example:
delete object.property or delete object[‘property’]

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

JAVASCRIPT-OBJECTS

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
24
Q

JAVASCRIPT-ARRAYS

What are arrays used for?

A

Array are used for storing values in a grouped list like a grocery list where orders are not essential;

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

JAVASCRIPT-ARRAYS

Describe array literal notation.

A

var array = [ ]

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

JAVASCRIPT-ARRAYS

How are arrays different from “plain” objects?

A

Objects have individual assigned properties but arrays have automatic number indexes assigned

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

JAVASCRIPT-ARRAYS

What number represents the first index of an array?

A

0 / Zero

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

JAVASCRIPT-ARRAYS

What is the length property of an array?

A

The length property is used to find the length of an array

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

JAVASCRIPT-ARRAYS

How do you calculate the last index of an array?

A

array.length - 1

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

JAVASCRIPT-FUNCTION

What is a function in JavaScript?

A

a reusable block of code

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

JAVASCRIPT-FUNCTION

Describe the parts of a function definition.

A

keyword, optional name, optional number of parameters, code, return

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

JAVASCRIPT-FUNCTION

Describe the parts of a function call.

A

name, ( ), and arguments

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

JAVASCRIPT-FUNCTION

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

A

function call doesn’t have keyword function and uses ( ) to call the function

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

JAVASCRIPT-FUNCTION

What is the difference between a parameter and an argument?

A
parameter = placeholder for potential value;
argument = actual value being placed in the argument;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

JAVASCRIPT-FUNCTION

Why are function parameters useful?

A

Function parameters are useful because they pass information to a function in order to be able to reuse the function code block

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

JAVASCRIPT-FUNCTION

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

A
1. Will replace the function called in that line of code;
Example:
function(3) = 10
var x = function(3) ... will become var x = 10
  1. Stops the function entirely once a value is returned
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

JAVASCRIPT-METHODS

Why do we log things to the console?

A

to debug our code, to check if our output is as expected, etc.

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

JAVASCRIPT-METHODS

What is a method?

A

function that is a property of an object

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

JAVASCRIPT-METHODS

How is a method different from any other function?

A

methods have to be called on an object;

functions do not;

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

JAVASCRIPT-METHODS

How do you remove the last element from an array?

A

pop( )

pop method

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

JAVASCRIPT-METHODS

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
42
Q

JAVASCRIPT-METHODS

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
43
Q

JAVASCRIPT-METHODS

How do you delete an element from an array?

A

pop for last item;
shift for first item;
splice for specific index

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

JAVASCRIPT-METHODS

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

A

push( )

Push method

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

JAVASCRIPT-METHODS

How do you break a string up into an array?

A

split(‘ ‘)

Split method

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

JAVASCRIPT-METHODS

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

A

does not change the original string;

To check: console.log( )

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

JAVASCRIPT-METHODS

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

A

About 50

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

JAVASCRIPT-METHODS

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

A

No, not in every situation

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

JAVASCRIPT-METHODS

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

A

A lot

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

JAVASCRIPT-METHODS

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

A

MDN

which stands for: Mozilla Developer Network

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

JAVASCRIPT-IF

Give 6 examples of comparison operators.

A
== is equal to;
!= is not equal to;
=== is strictly equal to;
!== is strictly not equal to;
> is greater than; < is less than;
>= is greater than or equal to;
<= is less than or equal to;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
52
Q

JAVASCRIPT-IF

What data type do comparison expressions evaluate to?

A

Boolean (true or false)

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

JAVASCRIPT-IF

What is the purpose of an if statement?

A

An if statement evaluates (or checks) a condition.

Let the computer make a decision based on conditions.

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

JAVASCRIPT-IF

Is else required in order to use an if statement?

A

no, only if you want to provide more than one set of code / another execution

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

JAVASCRIPT-IF

Describe the syntax (structure) of an if statement.

A

if (condition)…

instruction: { } else { }

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

JAVASCRIPT-IF

What are the three logical operators?

A

&& (and) ;
|| (or);
! (not);

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

JAVASCRIPT-IF

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

A

&& (and);

|| (or);

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

JAVASCRIPT-LOOPS

What is the purpose of a loop?

A

To continuously iterate through a code block until the condition is met
Allows us to repeat a certain function

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

JAVASCRIPT-LOOPS

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

A

To know when to stop the loop

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

JAVASCRIPT-LOOPS

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

A

Iteration = looping through once

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

JAVASCRIPT-LOOPS

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

A

At the start of every loop

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

JAVASCRIPT-LOOPS

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

A

Before the loop begins and only once

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

JAVASCRIPT-LOOPS

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

A

Before each iteration

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

JAVASCRIPT-LOOPS

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

A

After each iteration

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

JAVASCRIPT-LOOPS
Besides a return statement, which exits its entire 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
66
Q

JAVASCRIPT-LOOPS

What does the ++ increment operator do?

A

increments by 1

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

JAVASCRIPT-LOOPS

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
68
Q

DOM-QUERYING

Why do we log things to the console?

A

To see what we’re doing and for debugging

69
Q

DOM-QUERYING

What is a “model”?

A

representation of something

70
Q

DOM-QUERYING

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

A

the html document

71
Q

DOM-QUERYING

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

A

object is a data type

72
Q

DOM-QUERYING

What is a DOM Tree?

A

organization of/chunk of document

representative chunk of the page that shows the element and their element’s configuration

DOM = model that represents an html document in the form of javascript data types

73
Q

DOM-QUERYING

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

A

document. querySelector( );

document. getElementById( );

74
Q

DOM-QUERYING

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

A

document.querySelectorAll( )

75
Q

DOM-QUERYING

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

A

to be able to use it again in the future

76
Q

DOM-QUERYING

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

A

console.dir( )

Console.dir( ) is the way to see all the properties of a specified JavaScript object in console by which the developer can easily get the properties of the object.

77
Q

DOM-QUERYING

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

A

HTML loads from top to bottom and the elements need to load first

78
Q

DOM-QUERYING

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

A

The document.querySelector( ) takes
a css selector as an argument
and
returns first one that matches

79
Q

DOM-QUERYING

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

A

The document.querySelectorAll( ) takes
a css selector as an argument
and
returns a NodeList

80
Q

DOM-EVENTS

Why do we log things to the console?

A

In this exercise…

to debug and check if action happened

81
Q

DOM-EVENTS

What is the purpose of events and event handling?

A

when user does something, another thing happens

  • something that happens
  • to set up a list of action whenever an event occurs
82
Q

DOM-EVENTS

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

A

no they are not;

3rd parameter of addEventListener is optional

83
Q

DOM-EVENTS

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

A

addEventListener( )

84
Q

DOM-EVENTS

What is a callback function?

A

a function that is called as an argument in another function

85
Q

DOM-EVENTS

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

A

an object that is built in the moment as a reference of data

all relevant data is created, therefore you could get specific information in that one specific occurrence

86
Q

DOM-EVENTS

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

A

the button that you interact with;

target = the dom element where the event originated from;

If you weren’t sure, then console.log(event.target);

You could get more information about it in MDN

87
Q

DOM-EVENTS
What is the difference between these two snippets of code?
element.addEventListener(‘click’, handleClick)

element.addEventListener(‘click’, handleClick( ) )

A

2nd one is an anonymous function which may result in undefined.
- Always gets called without having to click it

88
Q

DOM-MANIPULATION

What is the className property of element objects?

A

Property that can get or set the value of class attribute

89
Q
DOM-MANIPULATION
How do you update the CSS class attribute of an element using JavaScript?
A

Use the className property on an element;

select your element.className = new value;

90
Q

DOM-MANIPULATION

What is the textContent property of element objects?

A

to get or set a text element

91
Q

DOM-MANIPULATION

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

A

select your element.textContent = ‘sample’

92
Q

DOM-MANIPULATION

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

A

No, if it’s not necessary, then no need.

93
Q

DOM-MANIPULATION

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

A

More complicated if we did not have variable

94
Q

DOM-MANIPULATION

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

A

Makes it easier to know what’s going on in your own code.

Store it in Javascript in variables and use that data to influence the DOM.

95
Q

JAVASCRIPT-FORMS

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

A

focus event

96
Q

JAVASCRIPT-FORMS

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

A

blur event

97
Q

JAVASCRIPT-FORMS

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

A

input event

98
Q

JAVASCRIPT-FORMS

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

A

submit

99
Q

JAVASCRIPT-FORMS

What does the event.preventDefault() method do?

A

Stops the default behavior from happening

In this exercise… stop browser from refreshing

100
Q

JAVASCRIPT-FORMS

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

A

Refreshes the page;

B/c of the action attribute (outdated)

101
Q

JAVASCRIPT-FORMS

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

A

elements property

102
Q

JAVASCRIPT-FORMS

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

A

value

103
Q

JAVASCRIPT-FORMS

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

A

Realizing it doesn’t work

104
Q

JAVASCRIPT-FORMS

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

A

Can check to see if your code works as you’re working on it

105
Q

DOM-CREATION

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

A

No, just creates a node;

You would still have to append it;

106
Q

DOM-CREATION

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

A

appendChild( ) method

107
Q

DOM-CREATION

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

A

pass two stings;

setAttribute ( name of attribute, value we wanna set attribute to);

108
Q

DOM-CREATION

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

A

create an element, querySelect for parent, generate child element

Example:
var h1 =
document.createElement(‘h1’)
someDiv.appendChild(h1)

109
Q

DOM-CREATION

What is the textContent property of an element object for?

A

To append text to a node and for looking at current text / to get or set text content
You can also check the text with textContent

110
Q
DOM-CREATION
Name two ways to set the class attribute of a DOM element.
A

setAttribute( );
Example:
setAttribute(‘className’, ‘classValues’)

class.Name;
Example:
element.className = ‘class’

111
Q

DOM-CREATION

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

A
  • saves a lot of time

- makes it reusable

112
Q

DOM-EVENT-DELEGATION

What is the event.target?

A

event.target is

where the event originated from

113
Q

DOM-EVENT-DELEGATION

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

A

event bubbling

114
Q

DOM-EVENT-DELEGATION

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

A

event.target.tagName

115
Q

DOM-EVENT-DELEGATION

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

A

The element.closest( ) method take as its argument… a CSS selector;
It matches it with closest ancestor (parent) element

116
Q

DOM-EVENT-DELEGATION

How can you remove an element from the DOM?

A

call the remove method on the element we want removed

element.remove( )

117
Q

DOM-EVENT-DELEGATION
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

addEventListener to the parent element;

use tagName method to check if you’re targeting the right element;

118
Q

JAVASCRIPT-VIEW-SWAPPING

What is the event.target?

A

Where the event originated from

119
Q

JAVASCRIPT-VIEW-SWAPPING

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

A

It will hide the element from the viewer

120
Q

JAVASCRIPT-VIEW-SWAPPING

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

A
The element.matches ( ) takes as an argument...
css selectors 
and
returns
a boolean value
121
Q

JAVASCRIPT-VIEW-SWAPPING

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

A

In order to retrieve the value of an element’s attribute,

call it on the DOM element

122
Q

JAVASCRIPT-VIEW-SWAPPING

At what steps of the solution would it be helpful to log things to the console?

A

Every Step

123
Q

JAVASCRIPT-VIEW-SWAPPING
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 an event listener for each individual element

124
Q

JAVASCRIPT-VIEW-SWAPPING
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

You would have to write many conditional statements

125
Q

JAVASCRIPT-AND-JSON

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).

In summary;
JavaScript Object Notation and lets us store them that is not in memory space

126
Q

JAVASCRIPT-AND-JSON

What are serialization and deserialization?

A

Converting a native object to a string so it can be transmitted across the network is called serialization;

Converting a string to a native object to be able to transmit is called deserialization

127
Q

JAVASCRIPT-AND-JSON

Why are serialization and deserialization useful?

A

JSON exists as a string — useful when you want to transmit data across a network.
It needs to be converted to a native JavaScript object when you want to access the data.

Breaks down data to byte size and easy to transmit data and load data throughout the web and store data

128
Q

JAVASCRIPT-AND-JSON

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

A

JSON.stringify( )

129
Q

JAVASCRIPT-AND-JSON

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

A

JSON.parse( )

130
Q

JAVASCRIPT-LOCAL-STORAGE

How do you store data in localStorage?

A

localStorage.setItem( keyName , keyValue )

131
Q

JAVASCRIPT-LOCAL-STORAGE

How do you retrieve data from localStorage?

A

localStorage.getItem( keyName )

132
Q

JAVASCRIPT-LOCAL-STORAGE

What data type can localStorage save in the browser?

A

Strings

133
Q

JAVASCRIPT-LOCAL-STORAGE

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

A

It is fired when the window, the document, and its resources are about to be unloaded.

134
Q

JAVASCRIPT-CUSTOM-METHODS

What is a method?

A

A method is a function stored within a property of an object.
Two kinds:
Instance Methods - built-in tasks performed by an object instance;’
Static Methods - tasks that are called directly on an object;

135
Q

JAVASCRIPT-CUSTOM-METHODS

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

A

Method call is conceptualized as a message (the name of the method and its input parameters) being passed to the object for dispatch.
Method definition is conceptualized as the shorthand for a function assigned to the method’s name.

136
Q

JAVASCRIPT-CUSTOM-METHODS

Describe method definition syntax (structure).

A
The method definition syntax (structure) may include:
var object = {
Property: function (anonymous or named) (parameters) {
steps of the function
}
};
137
Q

JAVASCRIPT-CUSTOM-METHODS

Describe method call syntax (structure).

A

The method call syntax (structure) may include:
The name of the method and its input parameters
Example:
- name of object. name of method(parameter)

138
Q

JAVASCRIPT-CUSTOM-METHODS

How is a method different from any other function?

A

A method, like a function, is a set of instructions that perform a task. The difference is that a method is associated with an object, while a function is not.

139
Q

JAVASCRIPT-CUSTOM-METHODS

What is the defining characteristic of Object-Oriented Programming?

A

The defining characteristic of Object-Oriented Programming is:
objects can contain both data (as properties) and behavior (as methods).

140
Q

JAVASCRIPT-CUSTOM-METHODS

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

A
Four "principles" of Object-Oriented Programming:
Abstraction,
Encapsulation,
Inheritance, 
Polymorphism
141
Q

JAVASCRIPT-CUSTOM-METHODS

What is “abstraction”?

A

An “abstraction” is a way to interact with a system in a simplified, consistent fashion. Involves the usage of data types, modeling and usage of procedures, functions, or subroutines which represent a specific of implementing control flow in programs.
- Control Flow: is the order in which individual statements, instructions or function calls of an imperative program are executed or evaluated

142
Q

JAVASCRIPT-CUSTOM-METHODS

What does API stand for?

A

Application Programming Interface (API)

- connection between computers or between computer programs

143
Q

JAVASCRIPT-CUSTOM-METHODS

What is the purpose of an API?

A

The purpose of software API is to give programmers a way to interact with a system (and functionality) in a simplified, consistent fashion.
Involves connection between computers or between computer programs.
One purpose of APIs is to hide the internal details of how a system works, exposing only those parts a programmer will find useful and keeping them consistent even if the internal details later change.

144
Q

JAVASCRIPT-THIS

What is this in JavaScript?

A

The object you’re working with currently. A variable whose value is the object you’re currently working with.

145
Q

JAVASCRIPT-THIS

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

A

Can use even though it is not explicitly declared in the function (present but not directly stated).

146
Q

JAVASCRIPT-THIS

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

A

Call time

147
Q

JAVASCRIPT-THIS

What does this refer to in the following code snippet?

A

this means nothing.. because it was never called

148
Q

JAVASCRIPT-THIS

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

A

“It’s a-me, Mario”

149
Q

JAVASCRIPT-THIS

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

A

“It’s a-me, undefined”

150
Q

JAVASCRIPT-THIS

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

A

We don’t know….

151
Q

JAVASCRIPT-THIS

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

A

the object to the left of the dot

152
Q

JAVASCRIPT-PROTOTYPES

What kind of inheritance does the JavaScript programming language use?

A

JavaScript includes a specific kind of inheritance known as prototype-based (or prototypal) inheritance where JavaScript objects give certain behaviors (methods) or data (properties) to other objects.

153
Q

JAVASCRIPT-PROTOTYPES

What is a prototype in JavaScript?

A

Prototypes are the mechanism by which JavaScript objects inherit features from one another.

154
Q

JAVASCRIPT-PROTOTYPES
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 inheritance

155
Q

JAVASCRIPT-PROTOTYPES

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

A

in the prototype

156
Q

JAVASCRIPT-CONSTRUCTORS

What does the new operator do?

A

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.

  • creates a new blank object
  • points to prototype of the function that made it
  • this becomes whatever object that was just made
  • returns that object if no other return is specified (which there shouldn’t be one)
157
Q

JAVASCRIPT-CONSTRUCTORS

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

A

Prototype property

stores an object and object holds shared data and behavior

158
Q

JAVASCRIPT-CONSTRUCTORS

What does the instanceof operator do?

A

The instanceof operator tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object. The return value is a boolean value.
- left being variable (whatever you want to check) and right being what you want to check the instance of

159
Q

JAVASCRIPT-TIMERS

What is a “callback” function?

A

A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.

160
Q

JAVASCRIPT-TIMERS
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

setTimout( ) method

- method sets a timer which executes a function or specified piece of code once the timer expires

161
Q

JAVASCRIPT-TIMERS

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

A

setInterval( )
- method, offered on the Window and Worker interfaces, repeatedly calls a function or executes a code snippet, with a fixed time delay between each call

162
Q

JAVASCRIPT-TIMERS

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

A

If delay parameter is omitted, a value of 0 is used, meaning execute “immediately”, or more accurately, the next event cycle.

163
Q

JAVASCRIPT-TIMERS

What do setTimeout() and setInterval() return?

A

The returned timeoutID is a positive integer value which identifies the timer created by the call to setTimeout( ).

164
Q

JAVASCRIPT-AJAX

What is AJAX?

A

AJAX is a technique for loading data into part of a page without having to refresh the entire page.

165
Q

JAVASCRIPT-AJAX

What does the AJAX acronym stand for?

A

Asynchronous Javascript And XML

166
Q

JAVASCRIPT-AJAX

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

A

XMLHttpRequest
Browsers implement an object called XMLHttpRequest to handle Ajax requests.
Once a request has been made, the browser does not wait for a response from the server.

167
Q

JAVASCRIPT-AJAX

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

A

load
- When the server has finished responding to the request, the browser will fire an event (just like it can fire an event when a page has finished loading). This event can be used to trigger a JavaScript function that will process the data and incorporate it into one part of the page (without affecting the rest of the page).

168
Q

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

A

prototypal inheritance