Skip to content

Instantly share code, notes, and snippets.

@oleksiilevzhynskyi
Created July 3, 2013 12:49
Show Gist options
  • Save oleksiilevzhynskyi/5917612 to your computer and use it in GitHub Desktop.
Save oleksiilevzhynskyi/5917612 to your computer and use it in GitHub Desktop.

Answer this questions to check you general understanding of the topic:

Quiz:

  1. How do you write a conditional statement for executing some code if i is equal to 5?

    • if (i==5)
    • if i=5
    • if i=5 then
    • if i==5 then
  2. What is an array?

    • A set of variables stored in one value
    • A set of several commands
    • A set of values stored in one variable
    • A set of several scripts
  3. How to declare a variable?

    • abc = ... and var abc = ...
    • Only abc = ...
    • Only var abc = ...
    • With neither of these
  4. What is result of next line of code?

     typeof null
    

    Answer:

    • null
    • object
    • undefined
  5. Which of the following function no exist for string?

    • reverse
    • replace
    • substring
    • concat
  6. When executed, what value will be alerted to the screen?

     function() {
         var a = 10;
         if (a > 5) {
             a = 7;
         }
         alert(a);
     }
    

    Answer:

    • 7
    • 10
    • null
    • undefined
  7. What would be the value alerted by this function?

     function() {
         if (true) {
             var a = 5;
         }
         alert(a);
     }
    

    Answer:

    • 0
    • 5
    • null
    • undefined
  8. Assuming I call these functions in order, what value gets alerted?

     var a = 5;
     function first() {
         a = 6;
     }
     function second() {
         alert(a);
     }
    

    Answer:

    • 5
    • 6
    • null
    • undefined
  9. There are now two variables with the same name, a. Which one does Javascript pick?

    var a = 5;
    function() {
        var a = 7;
        alert(a);
    }
    

Answer: * 5 * 7

  1. When executed, this will pop up three alerts. In order, what are they?

    var a = 6;
    function test() {
        var a = 7;
        function again() {
            var a = 8;
            alert(a);  // First
        }
        again();
        alert(a);  // Second
    }
    test();
    ​alert(a);​  // Third
    

Answer: * 6; 7; 8 * 7; 6; 8 * 8; 7; 6 * 8; 6; 7

  1. What's alerted to the screen?

    function getFunc() {
        var a = 7;
        return function(b) {
            alert(a+b);
        }
    }
    var f = getFunc();
    f(5);
    

Answer: * 5 * 7 * 12 * null

  1. JavaScript has Math library which can be used like this: Math.max(8,9,10) // result is 10. If I provide an array with certain values then how would you find the max value for that array.

    a = [1,2,3]; //write you code below
    
  2. In the following example, what is foo aliased to?

    (function(foo) {
      // What is 'foo' aliased to?
    })(this);
    

Answer: * undefined * global object (window) * null * this

  1. What is the result of next line of code?

    "b,ab,sb,".search(/b,/)

Answer: * -1 * 0 * 3 * undefined

  1. What will be alerted?

    var f = new Booleand(false); if (f) { alert(f); }

Answer: * nothing * undefined * false * true

Question to all topics:

  1. Implement the bubble sort.

  2. Why do these yield different results?

     '1' + 2 +  3 ; // Equals '123'
     3  + 2 + '1'; // Equals '51'
     3  + 2 +  1 ; // Equals 6
    
  3. Describe how variable hoisting works, and how to avoid bugs that may arise from it.

  4. How do these differ?

     function foo() {}
     // versus
     var foo = function() {};
    
  5. Explain how to determine if a variable is an array or an object.

  6. In one line of code, how you would make a copy of an array?

  7. What does this snippet of code do?

     var foo = bar ? bar : 0;
    
  8. When might you write something like this, and what is it shorthand for?

     foo && foo.bar();
    
  9. How do parseInt and parseFloat differ? When would you use a number's toFixed() method? In what instance might the following code snippet actually make sense to use?

      var my_number = my_string - 0;
    
  10. Write a function wich finds all the phone numbers in text (> 10000 chars) and replaces them with the name of the country. If number starts with +380 replace by Ukraine, +7 - Russia, +1 - USA, other - N/A.

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