Advanced JavaScript Flashcards

1
Q

What are Objects in Object-Oriented programming?

A

Objects are a way to categorize behavior and data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are objects in JavaScript?

A

They’re collections of named properties and methods, and they can be created on the fly using the object literal syntax

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a grouping of data and behavior into an object entity?

A

Encapsulation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

An object inherits properties and methods from another object.

A

Inheritance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

In JavaScript, what is prototypal inheritance?

A

This means that, when an object inherits from another, the parent object is known as the child’s prototype.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What two references does an object maintain with prototypal inheritance?

A

Every object maintains a reference to its prototype and every object inherits from the global object object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What will JavaScript return if an object property doesn’t exist?

A

undefined

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How does multiple inheritance work in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the constructor pattern?

A

A function called a constructor is used to create new objects. Constructors are used in combination with the new keyword to create objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is this code doing?

var Person = function (name) {
    this.name = name;
};

var tom = new Person(‘tom’);

A

Implementing the constructor pattern to create new Person’s objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What function makes it possible to create, modify and insert elements from JavaScript?

A

createElement

Example: var div = document.createElement(‘div’);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the appendChild method used for?

A

All elements have the appendChild method that allows you to append an element to it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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.

A

removeChild

Example: div.parentNode.removeChild(div);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

________ is a new DOM API for drawing on a 2- or 3-dimensional plane.

A

Canvas

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the 3D canvas web technology?

A

WebGL

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How does canvas animation work?

A

By repeatedly clearing the canvas (or a section of it) and redrawing the scene.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Why is it very useful to be able to store information in the browser?

A

So that the information can be shared across different pages and browsing sessions.

18
Q

What are cookies?

A

Text files saved to a user’s computer.

19
Q

What is the difference between cookies and local storage?

A

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.

20
Q

How to save data with local storage?

A

localStorage.setItem

Example: localStorage.setItem(‘name’, ‘tom’);

21
Q

How to get data out of local storage?

A

localStorage.getItem

Example: var name = localStorage.getItem(‘name’);

22
Q

True or False? Local storage can only save strings.

A

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.

23
Q

_______ are often used to notify another piece of code that something went wrong when trying to carry out a task

A

Errors

24
Q

What is error creation also known as?

A

Throwing an error

25
Q

You can account for exceptions being thrown using a construct called a ________.

A

try-catch

26
Q

True or False? If an error is thrown in the try block it doesn’t prevent continued code execution

A

The error is passed into the catch block for you to deal with.

27
Q

Are error objects?

A

Yes. The error passed to the catch block (like a function) is an object with a message property you can use to see what went wrong.

28
Q

How should your code handle errors?

A

In almost all cases you’ll want to ensure your code handles errors gracefully. It’s worth learning when errors are likely to occur so that you can defend your code against them.

29
Q

What keyword is used to generate errors?

A

throw

30
Q

What is a good way to avoid errors?

A

Being defensive in your code with try-catch blocks and checking the type of input data received from users.

31
Q

________ are used to search and match strings.

A

Regular Expressions.

32
Q

What is regular expression literal syntax?

A

Regular expression literal syntax is designated by two forward slashes. Everything between is the expression:.

Example: var regex = /^[a-z\s]+$/;

33
Q

What string methods accept regular expressions?

A
  1. ) match

2. ) replace

34
Q

What is a ‘g’ flag used in regular expressions?

A

global flag that means the expression should match all occurrences, rather than just the first, which is what it does by default.

35
Q

Where do flags go in regular expressions?

A

Flags like ‘g’ or ‘i’ always go after the closing slash.

Example: text.replace(/(every|no)thing/gi, “something”);

36
Q

A ________ is a function that returns a function.

A

A closure

37
Q

In a closure which function is returned?

A

The inner function is returned and has access to the outer function’s variables due to functional scope.

38
Q

_________ is a platform for building servers in JavaScript, built on Google’s V8 JavaScript engine

A

Node

39
Q

What is npm?

A

Node Package Manager used to install others’ modules to make developing things easier.

40
Q

What is the key concept in software engineering is the idea of modularity in code?

A

Separating out the key functionality of your app. In a modular system a component can be swapped out at little cost, so long as the interface between the components remains the same. Similarly, different components can be worked on in isolation from each other.

41
Q

What is a sandbox?

A

Modules can be connected in a number of different ways - one way is with modules communicating only with a central event and resource management module, sometimes referred to as a sandbox, and not communicating directly with each other.

42
Q

What is Model-View-Controller (MVC) architecture is a way of structuring code within an application?

A

Model-View-Controller (MVC) architecture is a way of structuring code within an application.

  1. ) A model is concerned with the data in your app
  2. ) A view with displaying or outputting data
  3. ) A controller with the business logic and coordinating the models and views