Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
The Node.js Master Class - Prerequisites Test

The Node.js Master Class - Prerequisites Test

If you ace this 10-question quiz, you'll get 50% off your enrollment in the Node.js Master Class

Follow these instructions CAREFULLY

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.

Question 1

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


Question 2

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


Question 3

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


Question 4

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


Question 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


Question 6

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


Question 7

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


Question 8

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


Question 9

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


Question 10

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.

Answers

Answer 1

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.

Answer 2

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"

Answer 3

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.

Answer 4

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.

Answer 5

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"

Answer 6

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.

Answer 7

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.

Answer 8

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

Answer 9

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.

Answer 10

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment