• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/49

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

49 Cards in this Set

  • Front
  • Back
What is a closure
Closures are variables from the parent function that remain bound from the parent's scope.
What does typeOf return
1: Undefined
2: Null
3: Boolean
4: Number
5: String
Difference between == and ===
=== and !== are strict comparison operators and return true if the operands are equal and of the same type.

Null == Undefined // true
Null === Undefined // false
0==false // true
0===false // false, because they are of a different type
1== "1" // true, auto type coercion
1=== "1" // false, because they are of a different type
What is the difference between call and apply?
call() requires that you specify each parameter, explicitly. Where as apply() requires that you pass your arguments as an array.
How does variable scope work with functions?
Variables created outside of any function are accessible globally, anywhere.

Variables created inside a function are available only within that function and its descendants.
How can you avoid having to use an onload function?
Place the code at the bottom of the script at the end of the DOM.
How can you create privacy in JavaScript and what are some examples of its use?
Using a closure you can create private areas in your code. Usages might be a global namespace for your code, private data members for sensitive info and such.
How do you access an elements parent?
You can use element.parentNode;
How do you attach something to the DOM?
You can call appendChild on the document objects target.

Ex: document.body.appendChild(el);
How do you find an element by type on the page?
var obj = getElementsByTagName('p');

It returns a specific type of array - like object called a node list.
How do you find out what kind of tag a node is?
element.tagName;
How do you get or change an elements content?
using the innerHtml property.
How do you replace an element?
You call el.replaceChild( var_to_insert, el_it_comes_before );
How do you set an attribute on an element?
You call the setElement( ) method on a selected element.
How does textNode and innerHtml differ?
Using textNode will convert the objects html to a string whereas innerHtml will give you the content back as html.
How does the flow of a program work
As the code executes down the body of the code it iterates through each line and executes it one by one. When it encounters a function call it jumps into that function definition and the control of the program flow is then given to that function to execute.

While the function is running the main program must remember the point where it jumped into the function and what was going on there. This includes things like the variables available and their state. The place where this is stored is called the stack.

Once the body of the function called finishes executing, or a return keyword is hit, the control is returned to the main routine from the function using it.
How does variable scope work with functions?
Variables created outside of any function are accessible globally, anywhere.

Variables created inside a function are available only within that function and its descendants.
What are higher-order functions.
Functions that work on other functions.

function forEach(array, action) {
for (var i = 0; i < array.length; i++)
action(array[i]);
}

forEach(["Wampeter", "Foma", "Granfalloon"], print);
What are the different ways of creating a new object?
#1 - you can write:
var myObj = {};
and thus define it by an object literal. Then add to it with dot syntax.

#2 - Alternatively, you can write a function and then call the new keyword in front of it:
What are the two main ways to write faster more efficient code?
#1) Limit the amount of identifier lookups that take place by caching anything used multiple times inside a local variable.

#2) Manipulating the DOM as seldomly as possible.
What does a double negative "!!" operator mean?
!! placed in front of something casts the contents to a boolean.

EX.
var x = 1;
console.log(typeof x); //number

x = !!x;
console.log(typeof x); //boolean
What is a common technique used to sandbox your code's scope and state making it local instead of global?
Wrapping it all in a self invoking anonymous function or name spacing it in a global object.
What is a DOM level 0 event handler?
It is an old way of adding event listeners to objects. It is 100% supported by browsers but lacks the ability to attach multiple events per click. It has been abandoned in favor of the standard event model. Syntax for dom level 0 is:

obj.onclick = function(){
//some code here
};
What is an alternative way to select items in the DOM and how well is it supported?
document.querySelector( ) and document.querySelectorAll( ) and they accept css selectors.
What is an event and an event handler?
An event is something that happens in the browser. An event handler is a function that executes and "handles" the event by performing a sub routine.
What is capturing & bubbling?
capturing says the event take an outside in approach, starting at the html root level and then propagates down to the event target, being the actual item clicked.

Bubbling is the reverse. It takes an inside out approach and starts at its current event target and bubbles all the way up to the top.

This can be problematic bc if an event is capturing and propagating down it would fire every click event that is registered on elements it hits on the way to the target.
What is identifier lookup
When you use a variable name in Javascript it begins a process called identifier lookup where it looks for something with the same name.

It starts at whatever level of scope you are currently at and if not found it moves its way back up the "scope chain" until it resolves the name.

If it cant find the identifier you get undefined. If you overwrite a value locally that was originally defined in a higher scope you effectively temporarily change the value of that variable while youre in that function scope. This is called shadowing.
What is Lexical Scoping
It means the when a function executes it uses the data members that were around at the time it was defined, not when it is actually called.

Aka, functions take a snapshot of whats going on around their definition when they are called. This is what is know of as their 'scope'. Scope is basically what information the function knows about when it executes. As stated above, this has to do with what is around at the time of their definition.
What is the best practice, in terms of data integrity, for working with objects?
In order to get and set values of an object you should create a well defined interface. An interface is a set of methods that you use to read and manipulate the properties / state of an object.

In other languages these are called getters and setters or accessers and mutators.
What is the chrome shortcut to bring up the console? What about toggling the console?
Cmd + option + j
esc toggles the console.
What is the difference between pascal casing and camel casing.
Pascal casing is the same for all intensive purposes except fot the fact that the first letter is capitalized.

Javascript uses this for object naming.
What is the difference between var obj = { };
and var obj = new myObject( );
The second uses a constructor function. It does some setup behind the seen setting the constructor property as well as defining a prototype for the object. Method one simply instantiates the object from the default Object object.
What is the native JavaScript equivalent to jQuery's .prepend( ) ?
el.insertBefore( var_to_insert, el_it_comes_before );
What is the precursor to jQuery's $(document).ready( ) method?
window.onload(function(){
//Place all code here to run after dom loads
});
What is the process of adding text to an element.
1) You have to create the element that will hold the text.

2) Next you have to create and store a text node, with createTextNode( 'your text' );

3) Lastly append it to the element created in step one.
What is the stack and how does it work?
The stack is the context of the executing script.

While the function is running the main program must remember the point where it jumped into the function and what was going on there. This includes things like the variables available and their state. This is the stack.

Each time a new function is called from the main routine a new snapshot of the context has to be taken and added on top of the stack. This requires memory.

When the stack grows too large the browser dies and you get an error in the console.
What is the syntax for the standard event model and who supports it?
obj.addEventListener('click', functionToExecute , ' capturing' );

To remove an event just use removeEventListener with the same arguments as you used to add it.
What is the syntax for the ternary operator
( if condition ) ? true : false;

(direction === "true" ) ? nextSlide : previousSlide;
What method do you call and what object do you call it on to create a element? How does it work?
You call the createElement method on the document object. It works by accepting a string, which is the element type, and then returns an element object of the corresponding type.

This can then be appended.
When creating a jQuery plugin why do you wrap the main behavior in "return each"
It makes the function work on more than just one item in case the selector returns more than one thing in the selected collection. Otherwise it would only
What is the DOM
The Document Object Model (DOM) is an API for manipulating HTML and XML documents. It provides a structural representation of the document, enabling you to modify its content and visual presentation by using a scripting language such as JavaScript.
What is JavaScript namespacing?
Namespacing is used to bundle up all your functionality using a unique name. In JavaScript, a namespace is really just an object that you've attached all further methods, properties, and objects. It promotes modularity and code reuse in the application.
What is Strict Mode?
Throws errors for actions that are silly but didn't previously throw an error, for potentially unsafe actions. Disables functions that are poorly thought out.
How do you change the style/class on any element?
document.getElementById("myText").style.fontSize = "20";
Looping structures in JavaScript?
for, while, do-while
Errors
try/catch/finally blocks. Basically, you try to run code (in the try block between the braces), and execution is transferred to the catch block of code when/if runtime errors occur. When the try/catch block is finally done, code execution transfers to the finally code block. This is the same way it works in other languages like C# and Java.
Event bubbling
Event bubbling describes the behavior of events in child and parent nodes in the Document Object Model (DOM); that is, all child node events are automatically passed to its parent nodes. The benefit of this method is speed, because the code only needs to traverse the DOM tree once. This is useful when you want to place more than one event listener on a DOM element since you can put just one listener on all of the elements, thus code simplicity and reduction. One application of this is the creation of one event listener on a page's body element to respond to any click event that occurs within the page's body.
this keyword
Is a context-pointer and not an object pointer. Gives you the top-most context that s placed on the stack

Points to the currently in scope object that owns where you are in the code.
*In global scope it refers to the Window object.
*In an object created with new this refers to the object created.
*With event handlers this points to the object that generated the event
JavaScript types
Number, String, Boolean, Function, Object, Null, Undefined