Quiz time

Given the following code:

1;(function() {
2  $(function() {
3    console.log('app starts');
4  });
5})();

Question: What is the $(function(){})?
  1. self invoked function.
    ✖ No. There is no () at the end.
  2. jQuery ready handling function
    ✔ Corrcet
↑ Mouse down or touch to select answer

Question: What is the usage of the beginning semi-colon ; mark?
  1. Prevent the function being treated as function argument
    ✔ During concatenation, in special case, this will happen: someing_before(function....)()
  2. No use
    ✖ Sure it has a usage here
↑ Mouse down or touch to select answer

Question: When is the “app starts” printed to the console?
  1. After all the content and images loaded
    ✖ jQuery ready does not wait for images loading.
  2. After the DOM tree is loaded and elements are ready
    ✔ jQuery ready means the DOM/elements are ready to be reference.
↑ Mouse down or touch to select answer

Given the following code:

1(function(){
2  var hello = "world";
3  this.name = "Thomas";
4})();

Question: Is hello a global variable?
  1. Yes, it is in global scope.
    ✖ `hello` is local variable because var follows function scope.
  2. No, it is not accessible from global scope.
    ✔ var follows function scope. It exists until the function ends.
↑ Mouse down or touch to select answer

Question: Is name a global variable?
  1. Yes, it is in global scope.
    ✔ `this` here refers to the global context, so `name` is accessible in global scope.
  2. No, it is not accessible from global scope.
    ✖ `this` here refers to the global context, so `name` is accessible in global scope.
↑ Mouse down or touch to select answer

What’s next? We’re going to take a look at “Project 3 – Welcome Screen”.

overlaied image when clicked on thumbnail

Makzan | Mobile web app dev with phonegap | Table of Content