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