JavaScript Flashcards
Focused on Object Oriented Programming
What is a method?
Function stored as a value in an object
How can you tell the difference between a method definition and a method call?
Method definition is very similar to a function definition (no arguments being passed) while a method call would be the object.methodname(argument).
Describe method definition syntax (structure).
Function definition being assigned to a property of an object
Describe method call syntax (structure).
object.methodname(argument)
How is a method different from any other function?
Method is associated as an object while functions are independent.
What is the defining characteristic of Object-Oriented Programming?
Object can contain both data and methods (behavior)
What are the four “principles” of Object-Oriented Programming?
Inheritance, Polymorphism, Abstraction, Encapsulation
What is “abstraction”?
Taking complex problems and making it accessible. The best example is a light switch. There’s a lot that happens under the hood but to humans you just flick a switch.
What does API stand for?
Application Programming Interface
What is the purpose of an API?
Allows your products and services to communicate with other products and services without having to constantly build new connectivity infrastructure.
What is this in JavaScript?
Keyword referring to a variable that holds a value in an object you are working with
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 included in the function’s parameter list or declared with var
When is the value of this determined in a function; call time or definition time?
Call time. It technically does not have a value until the function is called.
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); } };
Nothing it has not been invoked yet
Given the character object, what is the result of the following code snippet (character.greet())? Why? var character = { firstName: 'Mario', greet: function () { var message = 'It\'s-a-me, ' + this.firstName + '!'; console.log(message); } }; character.greet();
You will get the message because it retrieves the object with the property value
Given the character object, what is the result of the following code snippet *var hello = character.greet; hello()? Why? var character = { firstName: 'Mario', greet: function () { var message = 'It\'s-a-me, ' + this.firstName + '!'; console.log(message); } }; var hello = character.greet; hello();
Undefined
How can you tell what the value of this will be for a particular function or method definition?
You can’t
How can you tell what the value of this is for a particular function or method call?
If there is a . it is always what is to the left of it
What kind of inheritance does the JavaScript programming language use?
Prototypal Inheritance
What is a prototype in JavaScript?
Object that a bunch of objects can build off of
How is it possible to call methods on strings, arrays, and numbers even though those methods don’t actually exist on objects, arrays, and numbers?
From prototypes
If an object does not have it’s own property or method by a given key, where does JavaScript look for it?
On the prototype
What does the new operator do?
- Creates a blank, plain JavaScript Object
- Adds a property to the new object (__proto__) that links to the constructor functions prototype
- Binds newly created object instances as ‘this’ context
- Returns this if the function doesn’t return an object
What property of JavaScript functions can store shared behavior for instances created with new?
Prototype Property