Skip to content

Instantly share code, notes, and snippets.

@victoralvarez84
Created September 29, 2015 13:52
Show Gist options
  • Save victoralvarez84/217fe465f11b5f2d8bc6 to your computer and use it in GitHub Desktop.
Save victoralvarez84/217fe465f11b5f2d8bc6 to your computer and use it in GitHub Desktop.
Quiz Week 6-2
//2. Why is 0.3 not the result of the following addition? How do you work around this peculiarity?
0.1 + 0.2; // Equals 0.30000000000000004
// A. the statement will not yield an answer of 0.3 because the + operator in this
// syntax is just adding data together, not doing an equation. The work around is:
// var x = (0.1 + 0.2)
//3. How do these differ?
function foo() {}
vs.
var foo = function() {};
// A. These two statments are interchangable and the only difference is in the how the programmer wrote them.
//4.In the following example, what is foo aliased to? (Hint: It is what this means.)
(function(foo) {
// What is 'foo' aliased to?
})(this);
// A. Foo is aliased to the current function in which it is passed as an argument.
//5. What is the difference between setInterval and setTimeout?
// A. setInterval will return a function on timed loop that will update itself according to
// to the specs the programmer sets. setTimeout will run the function one time and never update
// itself. This was crucial when being able to update the playing board in Tic-Tac-Toe.
//6.What does this snippet of code do?
var foo = bar ? bar : 0;
// A. this snippet of code creates an instance of foo and sets a count of the
// instance at 0.
//7.When might you write something like this, and what is it shorthand for?
foo && foo.bar();
// A. foo && foo(function(bar));
//8.What does the following log; function, number, object, or undefined?
function aaa() {
return
{
test: 1
};
}
console.log(number)(typeof aaa());
// A. The following is undefined because number was never defined.
//9.Does this statement evaluate to true or false?
10 > 9 > 8 === true;
// A. This statement would prove false because this statement is
// not the absolute equalivent of true.
//10.Describe how variable scope works. Explain how to create a closure using an IIFE ( immediately-invoked function expression).
// A. Scope works by containing variables within functions so you do not have scope leakage.
// Certain variables can have global scope because they will be used over and over
// in the program. Below is an example of a closure: The curly brackets contain the variable,
// creating closure.
// function foo(){
// var bar = x;
// return bar;
// };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment