Advanced JavaScript Flashcards
What are Objects in Object-Oriented programming?
Objects are a way to categorize behavior and data
What are objects in JavaScript?
They’re collections of named properties and methods, and they can be created on the fly using the object literal syntax
What is a grouping of data and behavior into an object entity?
Encapsulation
An object inherits properties and methods from another object.
Inheritance
In JavaScript, what is prototypal inheritance?
This means that, when an object inherits from another, the parent object is known as the child’s prototype.
What two references does an object maintain with prototypal inheritance?
Every object maintains a reference to its prototype and every object inherits from the global object object.
What will JavaScript return if an object property doesn’t exist?
undefined
How does multiple inheritance work in JavaScript?
Multiple objects can inherit from one single object, but one single object cannot inherit from multiple other objects although it can inherit from an object that inherits from another.
What is the constructor pattern?
A function called a constructor is used to create new objects. Constructors are used in combination with the new keyword to create objects.
What is this code doing?
var Person = function (name) { this.name = name; };
var tom = new Person(‘tom’);
Implementing the constructor pattern to create new Person’s objects.
What function makes it possible to create, modify and insert elements from JavaScript?
createElement
Example: var div = document.createElement(‘div’);
What is the appendChild method used for?
All elements have the appendChild method that allows you to append an element to it.
Each DOM element has a property that’s actually the DOM element’s parent. To remove an element, you call the ________ method of the parent, passing the child element you want to remove.
removeChild
Example: div.parentNode.removeChild(div);
________ is a new DOM API for drawing on a 2- or 3-dimensional plane.
Canvas
What is the 3D canvas web technology?
WebGL
How does canvas animation work?
By repeatedly clearing the canvas (or a section of it) and redrawing the scene.
Why is it very useful to be able to store information in the browser?
So that the information can be shared across different pages and browsing sessions.
What are cookies?
Text files saved to a user’s computer.
What is the difference between cookies and local storage?
Unlike cookies, local storage can only be read client-side — that is, by the browser and your JavaScript. If you want to share some data with a server, cookies may be a better option.
How to save data with local storage?
localStorage.setItem
Example: localStorage.setItem(‘name’, ‘tom’);
How to get data out of local storage?
localStorage.getItem
Example: var name = localStorage.getItem(‘name’);
True or False? Local storage can only save strings.
True
Storing objects requires that they be turned into strings using JSON.stringify
That also means the object must be run through JSON.parse on the way out of local storage.
_______ are often used to notify another piece of code that something went wrong when trying to carry out a task
Errors
What is error creation also known as?
Throwing an error