Instructions: Start with an empty string. As you answer each question, add the letter of that answer onto that string. You will end up with a 10-character string that looks something like this: ABCDABCDAB. This string is your coupon code. Use it on the site when completing your purchase of the course. The final checkout screen contains a coupon field, above the credit-card entry field. Paste the string in there. If you end up with the wrong string (because one of your answers is wrong), the coupon won't work at all. If you get stuck and can't figure out which answer is wrong, read the answer-explanations at the bottom of this gist.
Note: I rearrange the answers to the questions often. So the coupon code you retrieve here may only work for a few hours.
In the code snippet below, in which order will the statements log?
console.log('a');
setTimeout(function(){
console.log('b');
},1000);
console.log('c');
A) a b c
B) c b a
C) a b c b
D) a c b
In the snippet below, what is the value of foo?
var myArray = ['a','b','c'];
var foo = myArray[3];
A) a
B) b
C) c
D) undefined
In Javascript, why does this expression evaluate to false?
0.2 + 0.4 == '0.6'
A) You're comparing a string to a number. The types are different!
B) You should be using 3 equals signs
C) A ramification of floating point precision: 0.2 + 0.4 does not equal 0.6
D) I don't know
In the code snippet below, what will be logged to the console?
var foo = 3;
console.log(foo);
console.log(++foo);
console.log(foo++);
A) 3 4 4
B) 3 3 5
C) 3 4 5
D) 3 5 5
In the snippet below, what is the "type" of foo? In order words, if we use the "typeof" operator on foo, what will it return?
var foo = [1,2,3];
A) Object
B) Array
C) String
D) Buffer
In javascript, is zero truthy or falsy? In order words, will this expression evaluate to true or false?
0 ? true : false;
A) truthy
B) falsy
C) None of the above
In Javascript, what will be the value of foo?
var myArray = [1,2,3];
var foo = myArray.indexOf(4);
A) false
B) undefined
C) -1
D) 0
E) NaN
In the terminal: if I have a file foo.txt and I write
cp foo.txt newFoo.txt
What will be the result?
A) foo.txt will be renamed to newFoo.txt
B) The contents of foo.txt will be copied to newFoo.txt, which will be created
C) foo.txt will be opened, nothing will happen to newFoo.txt
In the terminal: if I have a file foo.txt and I write
mv foo.txt newFoo.txt
What will be the result?
A) foo.txt will be renamed to newFoo.txt
B) The contents of foo.txt will be copied to newFoo.txt, which will be created
C) foo.txt will be opened, nothing will happen to newFoo.txt
In the terminal, which command lists all of the files in a directory, including hidden files?
A) la
B) ls
C) ls -a
D) ls -hidden
E) la -h
F) list all
That's the end of the questions! Follow the instructions at the top of this page to get your 50% discount.
Thanks to Javascript's asynchronous nature, "b" will actually be logged out last, well after "c". This is using a 'timer' function called setTimeout, which allows you to delay execution of pieces of code. setTimeout, and a few other timers, are available in the Node.js runtime as well.
Since arrays start counting at position zero (myArray[0]), the position referenced above is actually the 4th position in the array, not the 3rd. And as you can see, there is no 4th position defined, so it will return "undefined"
As with many languages, the Node.js runtime (and JS in general) uses floating-point arithmetic when doing math. So in the above example: 0.2 + 0.4 doesn't equal 0.6. It actually equals 0.6000000000000001. Therefore, the expression above evaluates to false. Since we're using 2 equals signs instead of 3, the "types" are not actually the problem.
In javascript foo++ and ++foo have different behaviors. As you can see, ++foo increments foo and then returns the value to you. Whereas foo++ returns the current value of foo to you, and then increments it later.
This question trips up almost everyone. If it caught you, don't worry.
The answer is "object" because Javascript considers Arrays to just be an object with some special properties. So in this example:
var foo = [1,2,3];
When you console log out the "type" of foo (using Javascript's "typeof" operator), it says "object"
console.log(typeof(foo));
// "object"
Knowledge of this quirk comes in handy when you're parsing payloads / parameters and trying to validate that they are what you think they are. In this case, if the typeof(foo) equals "object" it might actually be an array. There's a few other ways to check to see if it's an array. One of them is:
console.log(foo instanceof Array)
// true
In reality, Objects are really just associative arrays, and Arrays are a kind of Object. But what matters here is that Javascript considers an Array's "type" to be "object"
Although most numbers are truthy, zero is not. Keep this in mind if you're ever trying to use an "if" statement with a variable that might be zero.
When looking for the index of a certain value (within an array), Javascript will return -1 if it can't find the element you're looking for. This can be confusing; you'd be forgiven for thinking "undefined" would be the right answer here.
In the shell, "cp" will copy whatever file you name. In this example, we copied foo.txt into a new file (which didn't yet exist) called newFoo.txt
Unlike "cp", the "mv" command actually moves the file contents from the original named file, to a new one you specify; leaving no trace of the old one. So in effect, it's simply renaming the file.
The "ls" command has a few arguments you can supply to it. This one is particularly useful as you'll regularly be working with hidden files (like .gitignore, for example).