JS Flashcards
Getters
Getters are methods that get and return the internal properties of an object
how to use type of
typeof 37 === ‘number’;
Different types: number, undefined, object, boolean, string, symbol, function
Setters
methods which reassign values of existing properties within an object. Let’s see an example of a setter method:
How to turn an integer to a string?
.toString()
How to turn a string into an integer?
Number(x)
How to use a getter
from a ‘get’ variable in the object.
console.log(robot.getLevel);
How to use a setter
from a ‘set’ variable in the object
robot.getLevel = 100;
What is a state?
A program’s state is its current condition in regards to stored memory, variables, etc. It’s state can change over time as new input is added or data is manipulated in some way.
What is recursion?
Recursion is when a function calls upon itself until it reaches some sort of base case.
What is routing?
SPAs are based on a single document model. This means that web applications’ lifespan happens on a single html page, along with the transitions between the different views. But since links no longer imply the fetching and generation of a new document, how are those transitions modelled? they are achieved by using a router.
What is a Javascript Router?
A Javascript router is a key component in most frontend frameworks. It is the piece of software in charge to organize the states of the application, switching between different views. For example, the router will render the login screen initially, and when the login is successfull it will perform the transition to the user’s welcome screen.
What is abstraction?
Abstraction is a method for arranging complexity of systems. Abstraction contains complexity to create building blocks which are easier to expand upon.
encapsulation
Encapsulation is the process of restricting direct access to data or objects. Instead, methods are created to access this data or objects.
polymorphism
The ability to create a variable function or object that has more than one form. With polymorphism the program responds correctly depending on input type.
How to get object keys
Object.keys(obj1)
How to get an array of key value pairs of an object
Object.entries(obj1)
How to add more key value pairs to an existing object
const newRobot = Object.assign(robot, {laserBlaster: true, voiceRecognition: true});
The “for…in” loop
for (key in object) { // executes the body for each key among object properties }
For instance, let’s output all properties of user:
let user = { name: "John", age: 30, isAdmin: true };
for (let key in user) { // keys alert( key ); // name, age, isAdmin // values for the keys alert( user[key] ); // John, 30, true