JavaScript Flashcards
What is the event.target?
where the event originated from
What is the affect of setting an element to display: none?
removed from the document flow
hides element
What does the element.matches() method take as an argument and what does it return?
How can you retrieve the value of an element’s attribute?
.getAttribute
At what steps of the solution would it be helpful to log things to the console?
every step
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?
create separate event listeners for every tab
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?
create conditional block for each view
What is JSON?
text based data format for representing data based on JavaScript object syntax
What are serialization and deserialization?
process of converting an object into a stream of bytes to more easily save or transmit
constructing a data structure or object from a series of bytes
Why are serialization and deserialization useful?
makes it easier to save or transmit data
How do you serialize a data structure into a JSON string using JavaScript?
JSON.stringify() method
How do you deserialize a JSON string into a data structure using JavaScript?
JSON.parse() method
How do you store data in localStorage?
.setItem() method
(key name, value)
How do you retrieve data from localStorage?
.getItem() method
(key/property name)
What data type can localStorage save in the browser?
string data type
When does the ‘beforeunload’ event fire on the window object?
when user refreshes or exit window
How can you tell the difference between a method definition and a method call?
Describe method definition syntax (structure).
Describe method call syntax (structure).
How is a method different from any other function?
What is the defining characteristic of Object-Oriented Programming?
objects can contain both data(as properties) and behavior(as methods)
What are the four “principles” of Object-Oriented Programming?
abstraction, encapsulation, inheritance, polymorphism
What is “abstraction”?
being able to work complex things in simple ways
What does API stand for?
application programming interface
What is the purpose of an API?
to enable applications to exchange data and functionality easily and securely
What is this in JavaScript?
refers to an object that is executing the current piece of code
What does it mean to say that this is an “implicit parameter”?
it is available in a function’s code block even though it was never declared with a variable or included in the function’s parameter list
When is the value of this determined in a function; call time or definition time?
call time
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);
}
};
character object
Given the above character object, what is the result of the following code snippet? Why?
character.greet();
It’s-a-me, Mario!
theres an object to the left of the function(method) being called
Given the above character object, what is the result of the following code snippet? Why?
var hello = character.greet;
hello();
It’s-a-me, undefined!
no object before function call
How can you tell what the value of this will be for a particular function or method definition?
you can’t, no way to know, waiting to be used
How can you tell what the value of this is for a particular function or method call?
object before the function(method) being called
What kind of inheritance does the JavaScript programming language use?
prototype-based (prototypal)
JavaScript objects give certain behaviors (methods) or data (properties) to other objects.
What is a prototype in JavaScript?
an object with shared behavior or data that can be stored in one place and shared with all created instances
the procedure in which JavaScript objects inherit features from one another
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?
“borrow” methods from prototype object
If an object does not have it’s own property or method by a given key, where does JavaScript look for it?
each prototype object
What does the new operator do?
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.
- created a blank, plain JavaScript object
- takes the value of the prototype property off the function being run with the new operator and make it a property of the new object
- makes new object this
- if nothing was returned(normally nothing is returned), the object created gets returned
What property of JavaScript functions can store shared behavior for instances created with new?
prototype
What does the instanceof operator do?
tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object, return value is a boolean
(object instanceof constructor)
What is a “callback” function?
function passed into another function as an argument
Besides adding an event listener callback function to an element or the document, what is one way to delay the execution of a JavaScript function until some point in the future?
setTimeout()
How can you set up a function to be called repeatedly without using a loop?
setInterval
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0
What do setTimeout() and setInterval() return?
positive integer value which identifies the timer created