js2 Flashcards

1
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
2
Q

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

A

document.querySelector(“.css-selector”)

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

javascript: To return an array of 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
4
Q

javascript: To return an array of 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
5
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
6
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
7
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
8
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
9
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
10
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=/”;

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

javascript: To delete a cookie

A

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

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

javascript: To return the cookies on the browser, type

A

document.cookie;

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

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

A

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

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

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

A

semicolon

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

javascript: To use two conditional statements, use

A

double ampersand

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
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

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

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

A

it does not let the user return to the original page

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

javascript: To reload a window, type

A

window.location.reload();

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

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

A

jsonObject.key1

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

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

A

var myFile = require(“./myFile”)

nore: the ./ path is mandatory

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

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

A

module.exports.exposedFunctionName = localFunctionName;

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

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

A
function ConstructorFunc(param1) {
  this.attribute1 = param1;
  this.functionName = function() { console.log("string") }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

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

A

var myInstance = new ConstructorFunc(“param1”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
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")
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

javascript: By convention for constructor functions, people

A

capitalize the first letter

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

javascript: The DOM is

A

the javascript representation of the page

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
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”
}

28
Q

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

A

{ [varName]: “value” }

29
Q

javascript: To run an anonymous function

A

surround it with parentheses

30
Q

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

A

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

31
Q

javascript: The “document” object is contained in

A

the “window” object

32
Q

javascript: The “window” object contains

A

the url and the document, etc.

33
Q

javascript: The “window” object is

A

the global scope of your javascript, and contains any variables and methods you added

34
Q

javascript: To automatically return an array of all the images in the document, type

A

window.document.images

35
Q

javascript: To automatically return an array of all the scripts in the document, type

A

window.document.scripts

36
Q

javascript: To automatically return an array of all the forms in the document, type

A

window.document.forms

37
Q

javascript: a node is

A

an html element

38
Q

javascript: To trigger a function on click from the html, type

A

onclick=”functionName(‘param1’);”

39
Q

javascript: document.getElementsByTagName(“string”) returns

A

HTMLCollection, which is like an array

40
Q

javascript: To assign a function reference to a click handler, type

A

document.getElementById(“css-id”).onclick = functionName

41
Q

javascript: To create an html element, add an attribute to it, and then append it to the body, type

A
var elementName = document.createElement("tagname");
elementName.attribute = "value";

window.document.getElementsByTagName(“body”)[0].appendChild(divName);

42
Q

javascript: In the javascript console, to return an array of all the elements on the current page that have any css selector, type

A

document.querySelectorAll(“.css-class”)

43
Q

javascript: To add just one css property to an element, type

A

document.querySelector(“.css-class”).style[“property”] = “value”;

44
Q

javascript: javascript does not have

A

multiline strings

45
Q

javascript: var a = a || {} is used to

A

not override existing variables.

The new {} object is only assigned to “a” if the current value of “a” is falsey/undefined. If “a” already exists then it will not be overwritten and will be assigned back into itself.

46
Q

javascript: The break statement in a loop

A

stops the loop and continues the rest of the script.

47
Q

javascript: One way to preload an image is

A
imageInstance = new Image(10,10)
imageInstance.src = "http://cdn.com"
48
Q

css: The difference between display: none; and visibility: hidden; is

A

display: none; does not even render the tag into the dom, which visibility: hidden; does render the tag into the dom

49
Q

js: To pass the event object into a function from the onclick attribute, type

A

onclick=”functionName(event, param1)”

50
Q

A good general purpose npm library for all sorts of generators is

A

yeoman

51
Q

js: if you install a node module

A

using -g, then you do not need to specify the path when requiring?

52
Q

js: To send a text with twilio, type

A

client = require(‘twilio’)(‘accountsId’, ‘authToken’);

client.sendMessage({
to:’+972537227817’,
from: ‘+18186503041’,
body: ‘string’
}, function(err, responseData) {
if (!err) {
console.log(responseData.from);
console.log(responseData.body);
}
});

53
Q

js: Prototypal inheritance is

A

like class inheritance but with an object instead of a class

54
Q

js: The attribute of an object that changes when they inherit from another object is

A

objectName.__proto__ = parentObjectName

55
Q

js: The event that fires every time a user clicks out of the text box they are in is called

A

blur

56
Q

js: To run a function when someone clicks into an input, type

A

onfocus=”functionName()”

57
Q

js: The event that fires when someone clicks into an input is called

A

focus

58
Q

js: To check if a string passes a regex test, type

A

stringVar.match(/regex/i)

59
Q

js: To pass an inputs current value into an inline onclick function, type

A

onclick(“functionName(this.value)”)

60
Q

js: document.querySelectorAll() does not

A

return an array, so to iterate over it, put it in a var, and use a regular for () loop

61
Q

js: To remove an element, type

A
var elem = document.getElementById("myDiv");
elem.parentNode.removeChild(elem);
62
Q

js: To set and get variables from js after a page reload

A

localStorage.setItem(“varName”, “value”);

var varName = localStorage.getItem(“varName”);

63
Q

js: To insert a string into the html only if javascript is disabled on a browser, type

A

-noscript>string-/noscript>

64
Q

js: To automatically submit a form after it changes, type

A

onchange=”this.form.submit()”

65
Q

js: To dispatch an event with a customized event name, type

A
var myEvent = new Event('eventName', {bubbles: true})
document.body.dispatchEvent(myEvent)

Note:
document.body.click() is the same as above, but the eventName is “click”