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
Q

Which common HTML form element attribute indicates a function to be called when the element looses focus?

A

onBlur=”function()”

26
Q

Which object contains information about the browser?

A

navigator

27
Q

Which object and attribute gives you the browser?

A

navigator.appName

28
Q

What is the difference between null and undefined?

A

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
Q

What is the alternative to foo.bar if bar is not a string literal and a legal javascript name?

A

foo[“bar”]

30
Q

How are objects passed and handled?

A

By reference

31
Q

What is happens with ‘foo.bar = “Hello”’ when bar is not a property of foo?

A

foo is augmented with bar.

32
Q

What is a prototype?

A

An object linked to objects which provides properties that can be inherited.

33
Q

What are the conditional statements?

A

if and switch

34
Q

What are the looping statements?

A

for, while, and do

35
Q

What are the disruptive statements?

A

break, return, and throw

36
Q

What is label syntax for statements?

A

name : statement

37
Q

What values are false?

A

false, null, undefined, ‘’, 0, NaN

38
Q

What special properties do functions have?

A

constructor(code), this, arguments, outer context

39
Q
What kind of function is this?
var a = function (a,b) {
return a+b
}
A

anonymous

40
Q

What are the four ways to invoke a function?

A

function, method, constructor, and apply

41
Q

How is ‘this’ bound in a method?

A

‘this’ is bound to the object owning the method. It is bound late, at invocation time, which makes methods highly reusable.

42
Q

How is ‘this’ bound in a function?

A

‘this’ is bound to the global object. This means that inner functions in methods cannot see the object (workaround: var that = this).

43
Q

What type of inheritance does JavaScript use?

A

Prototypal Inheritance. Contrast with Classical-Inheritance. JS is class-free.

44
Q

What happens when a function is invoked with new?

A

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
Q

What is a constructor?

A

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
Q

What does ‘apply’ do?

A

Invokes a function with specified bindings for ‘this’ and arguments.

47
Q

What is returned from a constructor invocation?

A

If the return statement specifies an object, that object is returned. Otherwise, ‘this’ is returned.

48
Q

How can you make a method available to all objects?

A

Define the method on Object.prototype

49
Q

How do we augment all objects so that foo.method is supported for any object foo?

A

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.