JS test: Variables

Last modified by Sergiu Dumitriu on 2018/10/10 17:05

Task: Considering the following function:

  function foo()            //1
 {                         //2
      var a = 5;           //3
      b = 'Hello World';   //4
 }                         //5

Question: Which of the following are true:

  1. will not compile
  2. a is a local variable
  3. a is a global variable
  4. the javascript interpreter will throw an error on line 4
  5. b is a local variable
  6. b is a global variable