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
javascript: By convention for constructor functions, people
capitalize the first letter
26
javascript: The DOM is
the javascript representation of the page
27
javascript: To add a function to a constructor function that does not reload every time the constructor function is instantiated, use
ConstructorFuncName.prototype.functionName = function() { return "string" }
28
javascript: To evaluate the key name in a json object, type
{ [varName]: "value" }
29
javascript: To run an anonymous function
surround it with parentheses
30
javascript: To set the html of the body tag to a string, type
document.getElementsByTagName("body")[0].innerHTML = "script"
31
javascript: The "document" object is contained in
the "window" object
32
javascript: The "window" object contains
the url and the document, etc.
33
javascript: The "window" object is
the global scope of your javascript, and contains any variables and methods you added
34
javascript: To automatically return an array of all the images in the document, type
window.document.images
35
javascript: To automatically return an array of all the scripts in the document, type
window.document.scripts
36
javascript: To automatically return an array of all the forms in the document, type
window.document.forms
37
javascript: a node is
an html element
38
javascript: To trigger a function on click from the html, type
onclick="functionName('param1');"
39
javascript: document.getElementsByTagName("string") returns
HTMLCollection, which is like an array
40
javascript: To assign a function reference to a click handler, type
document.getElementById("css-id").onclick = functionName
41
javascript: To create an html element, add an attribute to it, and then append it to the body, type
``` var elementName = document.createElement("tagname"); elementName.attribute = "value"; ``` window.document.getElementsByTagName("body")[0].appendChild(divName);
42
javascript: In the javascript console, to return an array of all the elements on the current page that have any css selector, type
document.querySelectorAll(".css-class")
43
javascript: To add just one css property to an element, type
document.querySelector(".css-class").style["property"] = "value";
44
javascript: javascript does not have
multiline strings
45
javascript: var a = a || {} is used to
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
javascript: The break statement in a loop
stops the loop and continues the rest of the script.
47
javascript: One way to preload an image is
``` imageInstance = new Image(10,10) imageInstance.src = "http://cdn.com" ```
48
css: The difference between display: none; and visibility: hidden; is
display: none; does not even render the tag into the dom, which visibility: hidden; does render the tag into the dom
49
js: To pass the event object into a function from the onclick attribute, type
onclick="functionName(event, param1)"
50
A good general purpose npm library for all sorts of generators is
yeoman
51
js: if you install a node module
using -g, then you do not need to specify the path when requiring?
52
js: To send a text with twilio, type
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
js: Prototypal inheritance is
like class inheritance but with an object instead of a class
54
js: The attribute of an object that changes when they inherit from another object is
objectName.__proto__ = parentObjectName
55
js: The event that fires every time a user clicks out of the text box they are in is called
blur
56
js: To run a function when someone clicks into an input, type
onfocus="functionName()"
57
js: The event that fires when someone clicks into an input is called
focus
58
js: To check if a string passes a regex test, type
stringVar.match(/regex/i)
59
js: To pass an inputs current value into an inline onclick function, type
onclick("functionName(this.value)")
60
js: document.querySelectorAll() does not
return an array, so to iterate over it, put it in a var, and use a regular for () loop
61
js: To remove an element, type
``` var elem = document.getElementById("myDiv"); elem.parentNode.removeChild(elem); ```
62
js: To set and get variables from js after a page reload
localStorage.setItem("varName", "value"); var varName = localStorage.getItem("varName");
63
js: To insert a string into the html only if javascript is disabled on a browser, type
-noscript>string-/noscript>
64
js: To automatically submit a form after it changes, type
onchange="this.form.submit()"
65
js: To dispatch an event with a customized event name, type
``` 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"