JavaScript Flashcards
What is the effect of using document.write() in the HTML body?
It inserts text into the document at that point.
What is the effect of using document.write() in a function?
In this case, document.write() is called after the document has loaded, and overwrites the entire document.
V8
Chrome’s JavaScript engine, written by Google
node.js: process
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.
node: setTimeout and setInterval
Allow you to asynchronously schedule events. You never sleep in node.js
curl
library and command-line tool for fetching data using URLs over http, ftp, and many other protocols. Handles cookies, very powerful.
meta
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.
http-equiv
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.
Where does javascript go in an html doc?
In the header or else linked in from an external file.
What do legal javascript variables start with?
$ _ or a letter. Numbers can follow.
What are the data types in javascript?
Numbers, strings, booleans, and objects. (Arrays are objects).
What is Duck Typing?
It is a form of dynamic typing. In duck typing, an object’s methods and properties, rather than inheritance, determine its semantics.
How do you add a method to an existing object?
person[‘getBirthday’] = function() {
return ‘July 18th’;
};
Are javascript types completely dynamic type-inferred?
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.
What is the difference between “string” and ‘string’?
Nothing. Both forms work, and you can use one form to avoid escaping the other form ala:
“This isn’t hard.”
‘This is “hard”.’
What does javascript do if you use a variable which has not been previously declared?
Error. Stops execution.
How are javascript variables scoped?
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).
What is the associativity of +?
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).
CSS: What is .foo { } ?
class selector. Targets all elements with class=’foo’