Intermediate JavaScript Flashcards

1
Q

What is The Document Object Model?

A

A way to manipulate the structure and style of an HTML page. It represents the internals of the page as the browser sees it, and allows the developer to alter it with JavaScript.

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

HTML is an ______ structure in that the elements form a structure of parents’ nodes with children, like the branches of a tree.

A

XML-like

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

The DOM is also called?

A

The DOM tree

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

What is the root element of the DOM tree?

A

html

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

To access the DOM from JavaScript, the _______ object is used.

A

document

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

The document objects is provided by the _______ and allows code on the page to interact with the content.

A

browser

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

How do you get an element by its id?

A

document.getElementById

getElementById is a method of the document object

Example: 
var pageHeader = document.getElementById('page-header');
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the ways to retrieve an element?

A
  1. ) ID – getElementById
  2. ) Tag name – getElementsByTagName
  3. ) Class name – getElementsByClassName
  4. ) CSS selector – querySelector or querySelectorAll
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a NodeList?

A

An array of DOM Elements

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

What’s the difference between querySelector and querySelectorAll

A

querySelector, like getElementById, returns only one element whereas querySelectorAll returns a NodeList

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

What happens if multiple elements match the selector you pass to querySelector?

A

If multiple elements match the selector you pass to querySelector, only the first will be returned.

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

What is event-driven programming?

A

Writing interactive applications in JavaScript is often about waiting for and reacting to events, to alter the behavior of the browser in some way.

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

To react to an event you listen for it and supply a function which will be called by the browser when the event occurs. This function is known as a ________.

A

Callback

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

What is needed to listen for an event?

A
  1. ) The callback function
  2. ) An element
  3. ) The call to listen for an event
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

________ is a method found on all DOM elements used to add an event to listen for.

A

addEventListener

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

Developers got more ambitious with the web, attempting to build interactive applications sometimes called _______.

A

“native-like”

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

________ is a way to load new content into a page without a full reload.

A

AJAX

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

What does AJAX stand for?

A

Asynchronous JavaScript and XML

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

What is the underlying tech used to create AJAX pages?

A

XML HTTP Request (XHR)

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

Who originally created XMLHttpRequest?

A

Microsoft developing Outlook Web Access

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

What is the difference between asynchronous and synchronous calls?

A

If synchronous the execution of the code will pause at this line until the data is retrieved (blocking).

22
Q

XMLHttpRequest can load what kind of data over http and https or other protocols like FTP and file?

A

HTML, JSON, XML and plain text

23
Q

What is a single-page app?

A

One main request loads JavaScript code which then loads, asynchronously, other content from the server.

24
Q

What does JSON stand for?

A

JavaScript Object Notation

25
Q

What is JSON?

A

A set of text formatting rules for storing and transferring data in a machine and human readable way

26
Q

True or False? JSON is not JavaScript

A

True. It’s a totally different language with its own spec

27
Q

What is JSON used for?

A

JSON is used to transfer information - between your browser to a server, or saved in text files for retrieval later.

28
Q

True or False? JSON can’t store complex data like a function

A

True.

You can store arrays, objects containing simple data, strings and numbers.

29
Q

What technology is JSON replacing?

A

XML

30
Q

What method is used to create JSON?

A

stringify

31
Q

What method is used to retrieve JSON?

A

parse

32
Q

What does this do?

var car = JSON.parse(jsonString);

A

Parse JSON back into an object.

It could then be used:
Example: var car = JSON.parse(jsonString);
33
Q

What does scope mean?

A

Variable visibility

A variable’s scope is the part of your code that can access and modify that variable.

34
Q

What type of scope does JavaScript use?

A

Function SWcope

This means that variables are not visible outside of the function in which they were declared.

35
Q

What are global variables?

A

Variables that can be read and modified anywhere in your application

36
Q

Why are global variables bad?

A

They can expose security issues and make code much harder to maintain.

37
Q

What happens if variables are not declared inside a function?

A

They are available globally.

38
Q

_______ scope allows a function to see the variables of it’s parent function.

A

Child Scope

39
Q

What is the most popular DOM library?

A

jQuery

40
Q

What do DOM libraries do?

A

The set of tools used to allow modification and control of the DOM are a bit of mess because they differ across browsers, generally for historical reasons. To make your job easier, a number of libraries have been created that hide these differences, providing a more uniform way of interacting with the DOM. They also provide AJAX functionality.

41
Q

The way you interact with a service via code.

A

API – Application programming interface

42
Q

Why is it not always the best idea to use a DOM library?

A

jQuery is a large file to introduce to a page and will slow the downloading of that page, particularly on mobile browsers with potentially weak connections.

43
Q

$(‘.note’).css(‘background’, ‘red’).height(100);

A

Selects all the elements with a class of note on the page and then we set the background of all of the note boxes to red and their heights to 100px.

44
Q

What is the jQuery selector function?

A

$( )

A function that returns a jQuery wrapper around an element.

45
Q

What are methods that get and set the values of properties?

A

Getters and setters

46
Q

It’s sometimes useful to limit the area of the DOM from which an element can be selected. How is this done in jQuery?

A

Context

To tell jQuery which area you want to select from you pass a second argument that can be a DOM element, a string selector (selecting an element that jQuery will find and use) or a jQuery object. jQuery will only search within this context for your selector.

47
Q

What variable naming convention is used when storing jQuery objects?

A

The variable begins with a dollar sign.

Example: var $header

48
Q

What are the AJAX helper methods?

A
  1. ) $.get
  2. ) $.post
  3. ) $.ajax
49
Q

What does DOMContentLoaded do?

A

Run JavaScript only when the DOM is loaded and ready (but before stylesheets are fully loaded).

50
Q

What does this jQuery do?

$(window).load(doSomething);

A

Wait for the page to fully load - that is, when all stylesheets and images have been downloaded then doSomething.

51
Q

What type of type-checking functions does jQuery provide?

A
  1. ) $.isArray()
  2. ) $.isFunction()
  3. ) $.isNumeric()
  4. ) $.isPlainObject()