Javascript Flashcards

1
Q

D3: A good way to visualize binned data is

A

as shapes.

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

D3: The three most popular D3 libraries are

A

dimple.js, Rickshaw, NVD3

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

D3: The best D3 library for time series or streaming data is

A

Rickshaw

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

D3: The DOM gets created during

A

page load

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

Javascript: To clear the javascript console, type

A

clear()

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

Javascript: In the javascript console, to return the html of the current page that has a certain css id, type

A

document.getElementById(“cssid”)

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

Javascript: In the javascript console, to return the html of the current page that has a any css selector, type

A

document.querySelector(“.css-class”)

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

D3: To select elements using D3, type

A

d3.select(“.css-class”)

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

D3: To select a DOM element and then change its css styled color, type

A

d3.select(“.css-class”).style(“background-color”, “green”)

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

D3: To check if the element you are selecting is unique, you can type

A

d3.selectAll(“.css-class”)

and then make sure the array returned has one item.

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

D3: To select a DOM element and then change its text, type

A

d3.select(“.css-class”).text(“New Text”)

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

D3: To select an element within your current selection, type

A

current_selection_var.select(“.inner-class”)

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

D3: To change an html attribute, type

A

d3.select(“.css-class”).attr(“attribute_name”, “new value”)

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

javascript: To set a string to uppercase, type

A

string_var.toUpperCase()

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

javascript: To create a function, type

A
function fuctionName() {
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

javascript: To create an anonymous function, type

A
var functionVar = function () {
};

note: requires semicolon

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

javascript: To create a function that returns a string, type

A
function fuctionName() {
    return "string"
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

jQuery: To hide an html element with the class=”class”, type

A

jQuery(“.class”).hide();

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

jQuery: To show an html element with the class=”class” slowly, type

A

jQuery(“.class”).show(“slow”);

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

jQuery: The abbreviation for jQuery is

A

$

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

jQuery: Most jQuery methods return

A

the item selected, which allows for method chaining.

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

javascript: To return all of the html tags of the body of a page, type

A

document.body.children

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

javascript: To return all of the html tags on a page with a certain class name, type

A

document.getElementByClassName(“class”)

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

jQuery: In the jQuery docs, animations are categorized as

A

Effects

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

jQuery: To run a function when the DOM loads, type

A

$(document).ready(myFunction)
or
$(myFunction)

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

jQuery: When manipulating the DOM using javascript it is a best practice to

A

not create a script that runs on ready and just add your script at the bottom of the body and assume it is ready.

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

jQuery: To add html to an html element based on it’s class, type

A

$(“.class”).append(“-button>String-/button>”)

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

jQuery: To remove the code for the precise button you are clicking, type

A

$(“button”).click(function() {
$(this).remove();
});

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

jQuery: To traverse to the previous sibling page element before the element you selected by class, type

A

$(“.class”).prev()

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

jQuery: To prevent a link from taking you to the next page, type

A

$(“a”).click(function(event) {
event.preventDefault();
})

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

jQuery: To return the href of the link you just clicked, type

A
$("a").click(function() {
var my_attribute = $(this).attr("href");
})
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

jQuery: To turn a string into a jQuery representation of a page element, type

A

var $my_element = $(-div>-/div>)

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

jQuery: To signify that a variable is a jQuery object, people ofter

A

add a $ to the beginning of the variable name

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

jQuery: The append method appends to

A

the end but still inside the tags you point at.

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

jQuery: To use attr() to add an attribute to an element, type

A

$(“.class”)attr(“key”, “value”);

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

jQuery: To append text into a tag, type

A

$(“.class”).text(“string”)

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

ajax was originally called

A

xml http requestobject

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

ajax: To make a web page know that it will work with ajax, add to the head

A

-script>
var xhr_object = new XMLHttpRequest();
-/script>

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

ajax: a good response has the readyState value of

A

4

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

ajax: the servers response is held in an attribute called

A

xhr_object.responseText

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

ajax: To create a button that triggers the send method of an xhr_object, type

A
function sendAjax () {
    xhr_object.send()
}

-button onClick=”sendAjax()”>String-/button>

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

ajax: The steps to use ajax are

A

create an xhr_object
set a response function
open the request
send the request

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

ajax can only send requests to

A

one server

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

ajax: To overcome ajax’s one host policy you can

A

have your server call the additional servers.

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

ajax: To get images, css files and javascript files from an additional server, you can use

A

jsonp

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

javascript: To go to a different url, type

A

window.location.replace(“http://www.google.com”);

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

javascript: To return the url (including query string) of the current page, type

A

window.location.href

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

javascript: to slice a string, type

A

string_var.slice(1,5);

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

javascript: To return the index of a string, type

A

string_var.indexOf(“substring”);

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

javascript: To make a div immediately scroll itself to the bottom, type

A

document.getElementById(‘div-id’).scrollTop = document.getElementById(‘div-id’).scrollHeight;

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

javascript: To return the query string (including the “?”), type

A

window.location.search

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

AJAX: long polling is

A

When the client sends a request to the server and the server makes the client wait until an event occurs before sending the data back, and then the client makes another long request.

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

jQuery: To run a function upon every mouse movement, type

A

$(window).mousemove(function(event) {
console.log(event.type)
});

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

jQuery: To run a function when the mouse leaves the window, type

A

$(document).mouseleave(function(){
console.log(‘string’)
})

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

jQuery: To set or update a css property for a class, type

A

$(“.css-class”).css( “property”, “value”)

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

jQuery: To effectively remove a css property, type

A

$(“.css-class”).css(“property”, “”)

57
Q

javascript: To set a cookie on the browser, type

A

document.cookie=”key=a value; expires=Thu, 01 Jan 2016 12:00:00 UTC; path=/”;

58
Q

javascript: To delete a cookie

A

update it with an expiration date that is in the past.

59
Q

javascript: To return the cookies on the browser, type

A

document.cookie;

60
Q

javascript: To save the return of a confirm box into a var, type

A

var confirm_var = confirm(“Accept or Cancel?”);

61
Q

javascript: The return of a confirm box is

A

accept: true
cancel: false

62
Q

ajax: each different type of ajax request you plan to make should

A

have its own xhr_object

63
Q

ajax: The xhr_object attribute that contains the state of the request, e.g. 4 if the response has arrived, is

A

xhr_object.readystate

64
Q

javascript: To change the html that is within an element, type

A

document.getElementById(“id”).innerHTML = “new html”

65
Q

ajax: All the code necessary to send and receive an ajax request is

A
var xhr_object = new XMLHttpRequest();
xhr_object.onreadystatechange = function() {
if (xhr_object.readystate === 4) {
document.getElementById("id").innerHTML =       xhr_object.reponseText;
}};

xhr_object.open(“GET”, “/endpoint?key=value”)
xhr_object.send();

66
Q

jQuery: To send an ajax request and then inject it into a page element using jquery, type

A
function functionName() {
$(".css-class").load("/endpoint?key=value");
};
67
Q

javascript: At the end of if statements. do not put

A

semicolon

68
Q

javascript: User inputs that are numbers must be converted from

A

string to integer.

69
Q

javascript: The “equal to” operator for javascript conditional statements is

A

===

70
Q

javascript: To create a conditional statement, type

A

if (4 === 4) {
document.write(“Equal”);
}

71
Q

javascript: To create an if else clause, type

A
if (my_int === 4) {
    document.write("Equal");
} else {
    document.write("Not Equal");
}
72
Q

javascript: strict equality operators (===) do not

A

convert a string to a number.

== does

73
Q

javascript: The scrict not equals operator is

A

!==

74
Q

javascript: Boolean values in javascript are

A

written in lower case. eg. false, true

75
Q

javascript: An “else if” statement is written as

A

if () {
} else if () {
}

76
Q

javascript: To use two conditional statements, use

A

double ampersand

77
Q

javascript: To create a single line comment in a javascript file, type

A

//

78
Q

bower is a

A

front end package manager that allows you to easily download from one place.

79
Q

node: To print an error to the console, type

A

console.error(errorMessage);

80
Q

node: A callback function is

A

the function that executes when a response to a request is received.

81
Q

Javascript: To erase whatever is in the browser console, type

A

clear()

82
Q

Javascript: To return a rounded number from a float, type

A

Math.round(2.2)

83
Q

ajax: To send an ajax request for the next page of django’s pagination every time a user scrolls to the bottom, type

A
var is_active = false
var page_num = 1
$(window).scroll(function() {
   if(!is_active && $(window).scrollTop() + $(window).height() + 100 > $(document).height()) {
      $.get('http://endpoint.com?page=' + page_num, function(data){ 
      $(".gallery").append(data)
       is_active = false
        page_num += 1
       });
   }
});
84
Q

jQuery: jQuery selectors select matching elements that

A

exist in the DOM when the code is executed, and don’t dynamically update.

85
Q

jQuery: in order to keep dom objects selected even after the initial jQuery execution, (e.g. when loading new objects from ajax), you can use

A

$(document).on(“click”, “.css-class”, function() {

});

86
Q

maps: To render a map

A

import maps api before body end
-script src=”https://maps.googleapis.com/maps/api/js?key=API_KEY&callback=initMap” async defer>

create container div

<div></div>

var map;
function initMap() {
  var map = new google.maps.Map(document.getElementById('map'), mapOptions);
}

Note: must add mapOptions json to the initMap function before the map var

87
Q

maps: To get the coordinates of a device, type

A

navigator.geolocation.getCurrentPosition(success);

88
Q

maps: the success callback function of navigator.geolocation.getCurrentPosition(success); should start with

A
function success(pos) {
  var crd = pos.coords;
  var lat = crd.latitude;
  var lng = crd.longitude;
}
89
Q

javascript: To write code that will only execute after a set amount of time, type

A

setTimeout(function(){
console.log(“string”)
}, 2000);

note: this is 2 seconds

90
Q

ajax: To create an ajax request using $.get, type

A

$.get(‘http://endpoint.com?key=value’, function(data){
console.log(data);
});

91
Q

javascript: To turn an int into a string, type

A
var num = 15;
var n = num.toString();
92
Q

javascript: To simulate a button click, type

A

document.getElementsByTagName(‘button’)[0].click();

93
Q

javascript: When you use window.location.replace(“http://url.com”)

A

it does not let the user return to the original page

94
Q

maps: To disallow dragging, type

A
var mapOptions = {
    draggable: false,
  }
95
Q

maps: to create a marker, type

A
var marker = new google.maps.Marker({
  position: {lat: 11.111, lng: 22.222},
  map: map,
  title: 'String'
});
96
Q

jquery: To create a function that executes immediately, type

A

$(function() {

});

97
Q

javascript: To reload a window, type

A

location.reload();

98
Q

maps: To get all the data to the browser you should

A

send it all in json and then unpack it with javascript, rather than try to server side render

99
Q

maps: To make a marker with a new icon image, type

A
var marker = new google.maps.Marker({
  position: myLatLng,
  map: map,
  icon: 'http://cdn.com/file.png'
});
100
Q

ajax: get generic ajax loading gifs with a transparent background at

A

www.ajaxload.info/

101
Q

ajax: To make an ajax loading symbol come up

A

add a gif image to the bottom of the page display:none; and when you send the ajax request, set it to initial, and then back to none in the callback function

102
Q

javascript: To make a python style for loop in js, type

A

myArray.forEach(function(value, index) {
console.log(value);
})

103
Q

node: To import a library, type

A

var libraryName = require(“libraryName”)

104
Q

node: To turn a json string into a json object, type

A

JSON.parse(jsonString)

105
Q

node: To turn a json object into a json string, type

A

JSON.stringify(jsonObject)

106
Q

node: you can access value one in var jsonObject = {key1: “value1”} by typing

A

jsonObject.key1

107
Q

node: To import a file in the same directory, type

A

var myFile = require(“./myFile”)

nore: the ./ path is mandatory

108
Q

node: To expose a function to people importing your file, type

A

module.exports.exposedFunctionName = localFunctionName;

109
Q

node: To access any arguments you pass into the command line when running a script e.g. node script.js param1 param2, type

A

process.argv.slice(2)

110
Q

node: To go to a local host port, type the url

A

http://localhost:1337/

111
Q

node: To create a server, type

A

var http = require(‘http’);

var server = http.createServer(function (req, res) {
res.writeHead(200);
res.end(‘Hello, World!\n’);
});

server.listen(1337);

112
Q

node: After the function res.end() is executes inside the response

A

the browser stops listening for a response

113
Q

The local IP address for all computers is

A

127.0.0.1

114
Q

node: http.createServer(myFunction(req, res)); sends your function

A

an argument which is a request object with has and attribute called req.url, which returns everything after the root domain including get params

115
Q

javascript: To create an object using a constructor function, type

A
function ConstructorFunc(param1, param2) {
  this.attribute1 = param1;
  this.attribute2 = param2;
  this.functionName = function() { console.log("string") }
}
116
Q

javascript: To instantiate an object made by a constructor function, type

A

var myInstance = new ConstructorFunc(“param1”, “param2”)

117
Q

javascript: To turn a function call into a constructor function you must

A
precede the function name with "new"
e.g.
var myInstance = new ConstructorFunc("param1", "param2")
118
Q

javascript: By convention for constructor functions, people

A

capitalize the first letter

119
Q

javascript: To add a function to a constructor function that does not reload every time the constructor function is instantiated, use

A

ConstructorFuncName.prototype.functionName = function() {
return “string”
}

120
Q

javascript: The DOM is

A

the javascript representation of the page

121
Q

javascript: For websites that are rendering over 75KB of JSON data, time to first paint

A

is lower using server side rendering on both mobile and web

122
Q

javascript: For websites that are rendering below 75KB of JSON data, time to first paint is

A

about the same using client or server side rendering on both mobile and web

123
Q

javascript: For websites that are rendering over 75KB of JSON data, time to last paint fastest on

A

server side rendering on both mobile and web

124
Q

jquery: To return in inner html of a jquery object, type

A

$(“.css-class”).html()

125
Q

javascript: To evaluate the key name in a json object, type

A

{ [varName]: “value” }

126
Q

jquery: To scroll to bottom of div, type

A
var myDiv = $('.css-class');
var height = myDiv[0].scrollHeight;
myDiv.scrollTop(height);
127
Q

node: To update node, type

A

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

128
Q

javascript: To run an anonymous function

A

surround it with parentheses

129
Q

javascript: To create a script tag, add a src and type attribute to it and append it to the head, type

A

var elementName = document.createElement(“script”);

mf. type = “text/javascript”;
mf. async = true;
mf. src = “//www.cdn.com/id.js”;
document. getElementsByTagName(“head”)[0].appendChild(elementName);

130
Q

javascript: To set the html of the body tag to a string, type

A

document.getElementsByTagName(“body”)[0].innerHTML = “script”

131
Q

javascript: How jsonp works is

A

dynamically create a script tag with javascript
make the src the api endpoint you want
set the query string to ?callback=callbackFunctionName
this request will return your json data as an argument to a function named callbackFunctionName and will run the function so define the callback function that will handle the data before you make the dynamic script request
to return the data from api

132
Q

javascipt: Jsonp is

A

a way to overcome the single origin policy which prevents browsers from making an ajax request to a URL other than the current

133
Q

javascript: To run new javascript that was added to the page, type

A

eval(scriptName)

134
Q

javascript: To check if a browser has a touch screen or not, type

A
function isMobile() {
  try{ document.createEvent("TouchEvent"); return true; }
  catch(e){ return false; }
}
135
Q

jquery: To run a script only if the width of the screen is something, type

A
$(document).ready(function() {      
  var isMobile = window.matchMedia("only screen and (max-width: 760px)");

if (isMobile.matches) {

}
});

136
Q

javascript: To insert a new element into the top of a div full of elements, type

A

parentElement.insertBefore(newElement, parentElement.childNodes[0])

137
Q

javascript: To add a class to an element in vanilla js, type

A

document.querySelector(“div”).className += “ other-class”;

138
Q

jquery: To traverse up to the parent div then to the next div, then it’s children, type

A

$(element).parent().next().children()

139
Q

javascript: To start an html5 video at a certain spot after it loads, type

A

document.querySelector(‘video’).addEventListener(‘loadedmetadata’, function() {
this.currentTime = 10;
}, false);