JavaScript Flashcards

1
Q

What is the effect of using document.write() in the HTML body?

A

It inserts text into the document at that point.

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

What is the effect of using document.write() in a function?

A

In this case, document.write() is called after the document has loaded, and overwrites the entire document.

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

V8

A

Chrome’s JavaScript engine, written by Google

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

node.js: process

A

process takes the place of window in regular javascript, because node apps run on a server, not a browser window. Node allows you to write javascript in a console.

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

node: setTimeout and setInterval

A

Allow you to asynchronously schedule events. You never sleep in node.js

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

curl

A

library and command-line tool for fetching data using URLs over http, ftp, and many other protocols. Handles cookies, very powerful.

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

meta

A

HTML tag for providing metadata in key/value pairs. name=/content= pair used to specify generic metadata such as search terms (keywords), author, or description. Keys charset, http-equiv, and scheme(depr) offer other functionality.

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

http-equiv

A

Simulates an http header response with appropriate key/values. Key content-type specifies encoding (eg text/html), key refresh will reload a web page at intervals, key default-style will load CSS.

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

Where does javascript go in an html doc?

A

In the header or else linked in from an external file.

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

What do legal javascript variables start with?

A

$ _ or a letter. Numbers can follow.

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

What are the data types in javascript?

A

Numbers, strings, booleans, and objects. (Arrays are objects).

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

What is Duck Typing?

A

It is a form of dynamic typing. In duck typing, an object’s methods and properties, rather than inheritance, determine its semantics.

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

How do you add a method to an existing object?

A

person[‘getBirthday’] = function() {
return ‘July 18th’;
};

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

Are javascript types completely dynamic type-inferred?

A

Javascript types are dynamic. You can create a variable, assign a string, number, an object, then a different object. Run time errors will only be generated when you use the variable in a way that violates semantic rules for whatever its dynamic type happens to be.

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

What is the difference between “string” and ‘string’?

A

Nothing. Both forms work, and you can use one form to avoid escaping the other form ala:
“This isn’t hard.”
‘This is “hard”.’

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

What does javascript do if you use a variable which has not been previously declared?

A

Error. Stops execution.

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

How are javascript variables scoped?

A

Javascript variables are scoped to function, not block. Any extra ‘var’ declarations have no effect, where in other languages they may give you a new data store (such as declaring a variable in a loop).

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

What is the associativity of +?

A

Left-associative. This matters, for example, when your are stringing together strings and numbers. “3”+4+9 will result in 349, NOT 313 (4+9=13).

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

CSS: What is .foo { } ?

A

class selector. Targets all elements with class=’foo’

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

CSS: What is #foo { } ?

A

id selector. Targets all elements with id=’foo’. According to spec, there should be only one.

21
Q

CSS: What is foo { } ?

A

element selector. Targets all HTML elements of type .

22
Q

CSS: What is foo.goo { } ?

A

element by class selector. Targets all HTML elements of with class=’goo’.

23
Q

How do you fetch an array of all elements by type?

A

getElementsByType(‘TAGTYPE’) returns an array

24
Q

Under the W3C HTML DOM standard, what are five categories of nodes?

A
  • Document node (entire file)
  • Element node
  • Text node (text inside elements)
  • Attribute node
  • Comment node
25
Which common HTML form element attribute indicates a function to be called when the element looses focus?
onBlur="function()"
26
Which object contains information about the browser?
navigator
27
Which object and attribute gives you the browser?
navigator.appName
28
What is the difference between null and undefined?
undefined is a type and is assigned to variables that have been declared but not assigned (although it can be assigned literally). null is an object.
29
What is the alternative to foo.bar if bar is not a string literal and a legal javascript name?
foo["bar"]
30
How are objects passed and handled?
By reference
31
What is happens with 'foo.bar = "Hello"' when bar is not a property of foo?
foo is augmented with bar.
32
What is a prototype?
An object linked to objects which provides properties that can be inherited.
33
What are the conditional statements?
if and switch
34
What are the looping statements?
for, while, and do
35
What are the disruptive statements?
break, return, and throw
36
What is label syntax for statements?
name : statement
37
What values are false?
false, null, undefined, '', 0, NaN
38
What special properties do functions have?
constructor(code), this, arguments, outer context
39
``` What kind of function is this? var a = function (a,b) { return a+b } ```
anonymous
40
What are the four ways to invoke a function?
function, method, constructor, and apply
41
How is 'this' bound in a method?
'this' is bound to the object owning the method. It is bound late, at invocation time, which makes methods highly reusable.
42
How is 'this' bound in a function?
'this' is bound to the global object. This means that inner functions in methods cannot see the object (workaround: var that = this).
43
What type of inheritance does JavaScript use?
Prototypal Inheritance. Contrast with Classical-Inheritance. JS is class-free.
44
What happens when a function is invoked with new?
A new object is created. The object gets a hidden link to that function's prototype property, 'this' is bound to the new object, and the meaning of 'return' for that function is temporarily changed.
45
What is a constructor?
By invocation, it is a function called with 'new'. By declaration, it is simply a function intended to be used as a constructor. Because there are no restrictions on what can be called with 'new', it is important to maintain a convention of Capitalized Constructors.
46
What does 'apply' do?
Invokes a function with specified bindings for 'this' and arguments.
47
What is returned from a constructor invocation?
If the return statement specifies an object, that object is returned. Otherwise, 'this' is returned.
48
How can you make a method available to all objects?
Define the method on Object.prototype
49
How do we augment all objects so that foo.method is supported for any object foo?
Add the method to Object.prototype ala Object.prototype.method = function(){}. You can do the same with functions, arrays, regular expressions, strings, numbers, and booleans.